Adding data to Excel file

eTom

Registered User.
Local time
Today, 13:00
Joined
Oct 15, 2009
Messages
79
Hi all

I am having trouble getting my function to add data to an Excel worksheet before saving it to the desktop. It opens the template and saves the file just fine, but for some reason I can't get it to add anything to the sheet!

I've tried writing it from scratch and copy/pasting it from a similar function within a different module but haven't been able to get it to work. :banghead:

I know it's got to be something silly... anyone have some insight for me?

Thanks in advance,

eTom

Code:
    Dim OutputApp As New Excel.Application
    Dim OutputBook As Excel.Workbook
    Dim OutputSheet As Excel.Worksheet
    Dim TemplateFileName As String
    TemplateFileName = "c:\Users\Eric\Desktop\StoreReportTemplate.xltx"
    Set OutputApp = New Excel.Application
    OutputApp.Visible = False
    Set OutputBook = OutputApp.Workbooks.Add(TemplateFileName)
    Set OutputSheet = OutputBook.Sheets(1)

    OutputSheet.Cells(1, "B").Value = "Hello world."

Dim FileName As String
FileName = "c:\Users\Eric\Desktop\" & RegionName & " " & MonthNm & "-" & RunYear & ".xlsx"

'RegionName, MonthNm and RunYear are variables that eventually be defined by the function calling this subfunction.  For testing purposes they are defined as "Narnia", "Oct" and 2012 immediately after they are declared.
    
    OutputBook.SaveAs FileName
    OutputBook.Close False
    OutputApp.Quit
    Set OutputSheet = Nothing
    Set OutputBook = Nothing
    Set OutputApp = Nothing
 
Try this instead from Access VBA:

Code:
OutputSheet.Range("B1")= "Hello world."
 
Looks like a good solution to me. That should get etom going.
 

Users who are viewing this thread

Back
Top Bottom