personal excel macro causing access not to open excel file

D

Dustin

I set up a macro in "my personal folder" in excel. Now when I run the below
code in access it does not retrieve the correct excel file. Instead it opens
the "personal.xls" file. I have selected to hide the file, but when I run
the code it still opens the personal file.

Before I created the macro in excel, the access code worked perfectly.

Private Sub cmbreport_Click()

On Error GoTo Err_cmbreport_Click



MsgBox " This may take a minute, please be patient! ",
vbOKOnly, "Wait Time"

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "Top 50 High
Stores", "C:\Target Returns.xls", True

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "Item Detail
Top 50", "C:\Target Returns.xls", True

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "All Credits
All Stores", "C:\Target Returns.xls", True

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "Target Month
Gross Sales for", "C:\Target Returns.xls", True

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "Region",
"C:\Target Returns.xls", True

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "Group",
"C:\Target Returns.xls", True

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "District",
"C:\Target Returns.xls", True

MsgBox " Excel File C:\Target Returns.xls has been created /
replaced! ", vbOKOnly, "OUTPUT REPORT TO EXCEL"



Dim MyXL As Object, rst As DAO.Recordset

Dim strSQL As String



Set MyXL = GetObject("C:\Target Returns.xls")



MyXL.Application.Visible = True

MyXL.Application.WindowState = 3

MyXL.Parent.Windows(1).Visible = True

MyXL.Parent.ActiveWindow.WindowState = 2



Exit_cmbreport_Click:

Exit Sub



Err_cmbreport_Click:

MsgBox Err.Description

Resume Exit_cmbreport_Click

End Sub
 

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