Questions? Search our site or call us at 1-800-722-6004

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

Categories: Macro / Code Sample, Microsoft Excel, Data Collection, Serial (RS232), WinWedge

Last Updated: 2014.05.30

Need more help?

Don't hesitate to call or email us with your questions

Our office is open 9AM - 5PM Monday Through Friday (E.S.T.)

Technical Support: 215-496-0202

Toll-Free: 1 (800) 722-6004
Skype: taltech1 (Voice only)
Email: support@TALtech.com