Creating Excel Spreadsheet within Access VBA

G

Guest

I set up the code listed below to create an Excel spreasheet from within
access VBA which worked successfully except it displayed a warning message
when I wanted to save the file. I entered DoCmd.SetWarnings False which did
not work. I then entered: xlApp.Application.DisplayAlerts = False which
also did not work.
Do you know how this warning message can be turned off from within Access
for creating an Excel worksheet ? The code is listed below

Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
'Turn of Excel Alerts
xlApp.Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= _
path + file, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
End Sub
 
S

Steve Ripley via AccessMonster.com

I've used the following code

Dim FilePrefix as String ' Where to put it and partial name
DIM Report as Excel.Application
Dim XLS As Excel.Worksheet


FilePrefix = "C:\Some Dir\Report" ' destination file name and directory

Set Report = CreateObject("Excel.Application") ' start excel
Report.Workbooks.Add ' add worksheet
Set XLS = Report.ActiveSheet ' to make the reference
easier to type in the rest of the code

XLS.Name = FilePrefix & Space(1) & Format(Now(), "yyyy-mm-dd") ' give the
spreadsheet a name

..
.. Build spreadsheet here
..

XLS.SaveAs xls.Name ' write it

Set XLS = Nothing ' I leave Excel open so the report can be reviewed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top