Saving a Workbook Automatically in Excel

Our clients often wish to save their Excel workbook each time a new data record is logged. This can be done automatically via a VBA subroutine and is very easy to do if you are already using WinWedge in DDE mode with Excel. Simply add ThisWorkbook.Save to the end of your subroutine. For instance, the code might look something like this:

 Sub GetSWData()
   Dim R As Long, Chan As Long, vDat As Variant, sDat As String

   R = ThisWorkbook.Sheets("Sheet1").Cells(65000, 1).End(xlUp).Row + 1

   Chan = DDEInitiate("WinWedge", "Com1")
   vDat = DDERequest(Chan, "Field(1)")
   DDETerminate Chan

   sDat = vDat(1)
   ThisWorkbook.Sheets("Sheet1").Cells(R, 1).Value = sDat

   ThisWorkbook.Save
End Sub

Contact Us