Hello Guys,
Let me give you an idea of the project I am attempting and then my question...
I have a spreadsheet with a main Worksheet and then 10 extra sheets. The first sheet is my so called GUI. Here signals from various devices are collated and displayed live in a small list.
So, Channel 1 for example would be a reading of "O2" at "20.9%" This reading is passed onto worksheet 1 (1 of 10 channels) and then logged in a list along with the system time. On this page a dynamic graph is also generated.
On the main GUI sheet, channel 2 would be "CO2", this would be passed onto Worksheet 2 (2 of 10 Channels) and logged in a list the same as above...and so on..
So each worksheet after the main GUI is used for 1 channel measurement list and graph. So far so good.
Now, I have a save routine than runs every 30 mins and will save a file "Data20140727.xls" for example. The save routine only saves the worksheets 1 to 10 (data channels only). In this save routine, it will check if a file is ther or not. If not, it will create one. If a file however matching this name IS found then I need it to do something else...
This is where my current problem(s) lie. Let's say everything has been working well, then the computer crashes...restarts and begins to log data again. BUT this will create a new list of data for all the channels, so when it comes to save the file it will see one already exists. Here I need it to update /Merge the results.
Maybe it needs to open the file that already esists and run a VB macro to add the new data to the list??
Keep in mind, should the main XLS run fine and the computer does not crash, then the main file will have a continous list of data from the beginning. This is only for the case that the main XLS stops for any reason while logging.
While I am writing this, another idea springs to mind...when reopeing the main XLS with an Autostart comamnd, could I check to see if there is an existing file from that day and then copy the worksheets 1 t 10 in the NEW main XLS? Would that be easier?
I also have another question regarding the dynamic charts...but I will post a different topic for that one as not to confuse things...
Many thanks!!!
John
EDIT:::
This is what I came up with so far...but not working. It opens the file, copies as planned but then crashes out on the .PasteSpecial line...Any ideas?
Sub ImportData ()
Dim wb1 As Workbook
Dim wb2 As Workbook
Set wb1 = ActiveWorkbook
Dim Fname As String
Fname = "DataInterval" & Format(Now(), "yyyymmdd") & ".xls"
'Checks if file exists, if not carries on
If Dir(Fname) = (Fname) Then
Set wb2 = Workbooks.Open(Filename:=Fname)
wb2.Sheets(Array("O2", "Value2", "Value3")).Copy
wb2.Close savechanges:=False
ActiveWorkbook.Sheets (Array("O2", "Value2", "Value3")).PasteSpecial
End If
End Sub
Bookmarks