Archive for the ‘Tech Stuff’ Category

Batch convert XLS to CSV

Wednesday, May 2nd, 2007

Batch convert XLS to CSV.

This worked for me in Excel 2007.  Works great.  I saw software that does this for $19.99 up to $120.99.

After this you can Merge the CSVs into one file. 

Originally posted to a google group by Dave Peterson.


 

Option Explicit
Sub testme01()

    Application.ScreenUpdating = False

    Dim myFiles() As String
    Dim fCtr As Long
    Dim myFile As String
    Dim myPath As String
    Dim tempWkbk As Workbook
    Dim logWks As Worksheet
    Dim tempName As String
    Dim wks As Worksheet
    Dim oRow As Long

    ‘change to point at the folder to check
    myPath = "c:\my documents\excel\test"
    If Right(myPath, 1) <> "\" Then
        myPath = myPath & "\"
    End If

    myFile = Dir(myPath & "*.xls")
    If myFile = "" Then
        MsgBox "no files found"
        Exit Sub
    End If

    Set logWks = Workbooks.Add(1).Worksheets(1)
    logWks.Range("a1").Resize(1, 3).Value _
        = Array("WkbkName", "WkSheetName", "CSV Name")

    ‘get the list of files
    fCtr = 0
    Do While myFile <> ""
        fCtr = fCtr + 1
        ReDim Preserve myFiles(1 To fCtr)
        myFiles(fCtr) = myFile
        myFile = Dir()
    Loop

    If fCtr > 0 Then
        oRow = 1
        For fCtr = LBound(myFiles) To UBound(myFiles)
            Set tempWkbk = Nothing
            On Error Resume Next
            Set tempWkbk = Workbooks.Open(Filename:=myPath & myFiles(fCtr))
            On Error GoTo 0
            If tempWkbk Is Nothing Then
                logWks.Cells(oRow, "A").Value = "Error Opening: " _
                                                      & myFiles(fCtr)
                oRow = oRow + 1
            Else
                For Each wks In tempWkbk.Worksheets
                    With wks
                        If Application.CountA(.UsedRange) = 0 Then
                            ‘do nothing
                        Else
                            .Copy ‘to a new workbook
                            tempName = myPath & Trim(.Name) & ".csv"
                            Do
                                If Dir(tempName) = "" Then
                                    Exit Do
                                Else
                                    tempName = myPath & Trim(.Name) & "_" _
                                          & Format(Time, "hhmmss") & ".csv"
                                End If
                            Loop
                            oRow = oRow + 1
                            With ActiveWorkbook
                                .SaveAs Filename:=tempName, FileFormat:=xlCSV
                                .Close savechanges:=False
                            End With
                            logWks.Cells(oRow, "A").Value = myFiles(fCtr)
                            logWks.Cells(oRow, "b").Value = .Name
                            logWks.Cells(oRow, "C").Value = tempName
                        End If
                    End With
                Next wks
                tempWkbk.Close savechanges:=False
            End If
        Next fCtr
    End If

    With logWks.UsedRange
        .AutoFilter
        .Columns.AutoFit
    End With

    Application.ScreenUpdating = True

End Sub

If you’re new to macros, you may want to read David McRitchie’s intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Short course:
Start a new workbook
Hit alt-f11 to get to the VBE (where macros/UDF’s live)
hit ctrl-R to view the project explorer
Find your workbook.
should look like:   VBAProject (yourfilename.xls)  

right click on the project name
Insert, then Module
You should see the code window pop up on the right hand side

Paste the code in there.  

Modify the folder that contains the .xls files.
myPath = "c:\my documents\excel\test"
to what you need.

Now go back to excel.
Save your workbook (so you can run the macro)

When you want to run or rerun:
Open this workbook
(fix the folder name in the code if it changed)

click on Tools|macro|macros…
click on the macro name (testme01, but you can rename it!)
and then click run.

Backup Data from Windows using Knoppix Part 2

Thursday, April 5th, 2007
Q: I want to copy files to a windows box over the network

A:

  • Second Method

I boot with Knoppix from the CD drive. Once it has fully loaded to the KDE desktop, I open a konsole command window. I assume the the hda1 (C: drive) is a FAT32 drive, so I mount it with the command:

sudo mount -t vfat -o ro,users /dev/hda1 /mnt/hda1

If instead the the hda1 (C: drive) is a NTFS drive, the I mount it with the command:

sudo mount -t ntfs -o ro,users /dev/hda1 /mnt/hda1

Next I open up the GUI file manager (called konqueror).

sudo konqueror

Once that comes up, in the location bar, I use the following to authenticate to a Windows domain & then access a windows networking share.In the location bar:

smb:/domain\username@IP.address.of.machine

If you do not need to authenticate to a domain, the form is:

smb:/hostname

or

smb:/IP.address.of.machine

This allows me to access windows shares. I navigate to where I want to save the data, then hit the keys CTRL-T to open a tnew tabbed window. Then in that location bar type:

/mnt/hda1/

Now I see the hda1 (C: drive) contents. Just like in windows explorer, select the file & folders you want to copy, CTRL-C or right-click & copy them. Use the mouse & move over to the other tab with the smb connection, then CTRL-V or right-click paste to initiate the transfer. When you are done copying files, close the konqueror window, click the KDE K menu and choose to reboot/shutdown the PC. TO shutdown the PC by command:

sudo init 0
  • Other method, in which both directions are possible. Either start SAMBA or mount the remote share.
    • "sudo /etc/init.d/samba start", add users with "smbpasswd -a knoppix". After this, the home directory of user knoppix will be shared as readonly. If you need other shares, edit /etc/samba/smb.conf and restart samba (replace "start" with "restart").
    • "mkdir tmp/share; sudo mount -t smbfs -o username=Administrator //otherbox/share /tmp/share" (maybe start samba too to get rid of the warnings, especialy when using "nmblookup")
  • Or you can obtain a lissetup.sh ("wget http://users.volja.net/zejnovi/lissetup.sh" in console). After doing that, in console, type: "chmod +x lissetup.sh", and then "./lissetup.sh". After doing this, you can use the LAN browser in Konqueror.

Ajax Inline Editor with PHP and MySQL

Friday, March 30th, 2007

I found lots of scripts that do inline editing but I couldnt find one that updated the database.  This little beauty will, thanks to the Javascript from the link below.

My code is fairly sloppy but you get the idea from it.

Ok so using the js from the page below:
http://www.yvoschaap.com/index.php/weblog/ajax_inline_instant_update_text_20/

assuming you have a table called tblInLineEdit with fields id, name,descr

**ajaxtest.php**
<?
$db_user = "";
$db_pass = ""; // password here
$db = "";
$host = "";
$link = mysql_connect($host,$db_user,$db_pass) or die("Database connection broken");
mysql_select_db($db,$link) or die("Database connection unavailable - ".mysql_error() );
$result = mysql_query("SELECT * FROM tblInLineEdit");
//$row = mysql_fetch_assoc($result);
?>
<script type="text/javascript" src="instantedit.js"></script>
<table>
<? while ($row = mysql_fetch_assoc($result)) { ?>
<tr>
<td><span id="name-|||-<?php echo $row[’id’]; ?>" class="editText"><? echo $row[’name’]; ?></span></td>
<td><span id="descr-|||-<?php echo $row[’id’]; ?>" class="editText"><? echo $row[’descr’]; ?></span></td>
</tr>
<?php } ?>
</table>



**update.php**
<?
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0

$db_user = "";
$db_pass = "";
$db = "";
$host = "";
$link = mysql_connect($host,$db_user,$db_pass) or die("Database connection broken");
mysql_select_db($db,$link) or die("Database connection unavailable - ".mysql_error() );
$content = $_GET[’content’];
list($fieldname, $id) = explode("-|||-",$_GET[’fieldname’]);
mysql_query("UPDATE tblInLineEdit SET $fieldname = ‘$content’ WHERE id = $id ") or die("blah failure - ".mysql_error() );
$result = mysql_query("SELECT * FROM tblInLineEdit WHERE id = $id");
$row = mysql_fetch_assoc($result);
echo $row["{$fieldname}"];
?>

Converting to MS Office Accounting 2007 Pro with Business Contact Manager 2007

Monday, February 5th, 2007

Well this years action pack came from MS.  We've upgraded all the office computers to Office Enterprises 2007.

Next step is to convert from Quickbooks 2005 and Commence as our mish mash of CRM and Billing systems to a more stream lined Microsoft solution.  Since my SBS is not R2 and uses SQL2000 I'm going to host the BCM/Acounting database on a workstation until I upgrade the server. 

So here;s the step by step:

  1. Install Office 2007 Enterprise edition.
  2. Pick the "main" workstation where the DB is going to sit.
  3. Make sure you are an administrator on the machine you are using.
  4. Copy the QB datafile on to the local computer.
  5. install Office Accounting 2007
  6. Select import Quickbooks data
  7. sit and wait.  Its hour 4 now and it hasnt finished a 64MB .qbw

Slipstream Drivers and Windows Updates into XP CD

Thursday, February 1st, 2007

Just a rough draft.  This post needs to be cleaned up.

To start with here just some links to sites I need when updating an XP disc.

  1. Run the DP_Base.exe
  2. choose your lean XP folder
  3. Download upadated Driver packs to driverpacks folder
  4. slipstream them
  5. go get the latest post sp2 XP updates from the ryanvm site below. 
  6. check for latest Nlite also dig around for other addons as well.  dont get bloaty.
  7. run nlite and choose your xp folder
  8. choose integrate hotfix
  9. choose the addons and updates your downloaded
  10. remove the languages and keyboards from components
  11. enable SFC. (yeah we are a MS shop and sometimes run sfc /scannow  works. 

http://www.nliteos.com/

http://www.ryanvm.net/msfn/

http://driverpacks.net/