+ Reply to Thread
Results 1 to 3 of 3

Data Logging XLS Save to Exisiting or Copy from Existing

  1. #1
    Registered User
    Join Date
    08-01-2014
    Location
    Germany
    MS-Off Ver
    2012
    Posts
    5

    Data Logging XLS Save to Exisiting or Copy from Existing

    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

  2. #2
    Registered User
    Join Date
    08-01-2014
    Location
    Germany
    MS-Off Ver
    2012
    Posts
    5

    Re: Data Logging XLS Save to Exisiting or Copy from Existing

    I've now also tried .copy destination:=ThisWorkbook.Sheets(Array("O2", "Value2", "Value3")) Still not working..any ideas?

  3. #3
    Registered User
    Join Date
    08-01-2014
    Location
    Germany
    MS-Off Ver
    2012
    Posts
    5

    Re: Data Logging XLS Save to Exisiting or Copy from Existing

    Anyone....?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 11
    Last Post: 11-04-2013, 04:32 PM
  2. Replies: 3
    Last Post: 10-14-2013, 03:06 PM
  3. Replies: 0
    Last Post: 04-28-2012, 06:06 PM
  4. VBA to save data to new worksheet within the exisiting spreadsheet
    By mal.b.graham in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-05-2011, 04:40 AM
  5. Replies: 1
    Last Post: 06-10-2005, 08:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1