I am using the following code to make formatting changes to an Excel workbook that is created by an Access export process. The resulting file will then be emailed as an attachment.
The problem I am having is that when the resulting file is opened in Excel, the file is hidden. I then need to go through the Window/Unhide menu options to view the file.
Any suggestions?
Code:
Public Sub ChangePageSetup(FileName As String)
Dim objXLApp As Excel.Application
Dim objXLBook As Excel.Workbook
Dim objXLSheet As Excel.Worksheet
On Error GoTo Error_ChangePageSetup
Set objXLBook = GetObject(FileName)
Set objXLApp = objXLBook.Parent
Set objXLSheet = objXLBook.Worksheets("Pastdueorders"
With objXLSheet
.PageSetup.LeftMargin = objXLApp.InchesToPoints(0.5)
.PageSetup.RightMargin = objXLApp.InchesToPoints(0.5)
.PageSetup.TopMargin = objXLApp.InchesToPoints(0.5)
.PageSetup.BottomMargin = objXLApp.InchesToPoints(0.5)
.PageSetup.Zoom = 75
.PageSetup.Orientation = xlLandscape
.Columns.AutoFit
End With
objXLBook.Save
objXLApp.Application.Quit
Set objXLSheet = Nothing
Set objXLBook = Nothing
Set objXLApp = Nothing
Exit_ChangePageSetup:
Exit Sub
Error_ChangePageSetup:
MsgBox Err.Number & " " & Err.Description
Resume Exit_ChangePageSetup
End Sub
Scott
The problem I am having is that when the resulting file is opened in Excel, the file is hidden. I then need to go through the Window/Unhide menu options to view the file.
Any suggestions?
Code:
Public Sub ChangePageSetup(FileName As String)
Dim objXLApp As Excel.Application
Dim objXLBook As Excel.Workbook
Dim objXLSheet As Excel.Worksheet
On Error GoTo Error_ChangePageSetup
Set objXLBook = GetObject(FileName)
Set objXLApp = objXLBook.Parent
Set objXLSheet = objXLBook.Worksheets("Pastdueorders"
With objXLSheet
.PageSetup.LeftMargin = objXLApp.InchesToPoints(0.5)
.PageSetup.RightMargin = objXLApp.InchesToPoints(0.5)
.PageSetup.TopMargin = objXLApp.InchesToPoints(0.5)
.PageSetup.BottomMargin = objXLApp.InchesToPoints(0.5)
.PageSetup.Zoom = 75
.PageSetup.Orientation = xlLandscape
.Columns.AutoFit
End With
objXLBook.Save
objXLApp.Application.Quit
Set objXLSheet = Nothing
Set objXLBook = Nothing
Set objXLApp = Nothing
Exit_ChangePageSetup:
Exit Sub
Error_ChangePageSetup:
MsgBox Err.Number & " " & Err.Description
Resume Exit_ChangePageSetup
End Sub
Scott