Results 1 to 4 of 4

write data to a closed workbook

Threaded View

  1. #1
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,176

    write data to a closed workbook

    I am trying to fix code that:
    1 - opens a workbook
    2 - writes data to the workbook
    3 - saves workbook
    4 - closes workbook

    I am able to open the workbook needed. However, I am having an issue when I get to the "With Sheets("Log Record")" statement. The code is not looking at the file that was opened, it is looking at the other file. It appears that the newly opened file is not the active file. I can't figure out what is causing this. Thanks in advance for any comments.

    Sub UpdateMasterFile()
    
        Dim NextRow As Long
        Dim wsLog As Worksheet
            
        Workbooks.Open Filename:= _
            "F:\Projects\Metrics\New Process\Log User Login Times History.xls"
    
        With Sheets("Log Record")
            NextRow = .Range("A" & Rows.Count).End(xlUp).Row + 1
            .Range("A" & NextRow) = Date
            .Range("B" & NextRow) = Time
            .Range("E" & NextRow) = Environ("USERNAME")
            .Range("F" & NextRow) = Environ("COMPUTERNAME")
        End With
     
        ActiveWorkbook.Save
        ActiveWindow.Close
    
    End Sub
    Last edited by maacmaac; 11-24-2010 at 06:16 PM.

Thread Information

Users Browsing this Thread

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

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