Solved

MS Access VBA to insert Page Numbers into Excel with Read-Only display

Posted on 2013-06-11
2
534 Views
Last Modified: 2013-06-11
Hello Experts,

I am in the process of adding Page Numbers into an Excel workbook and when doing so, an error message appears that the workbook is read-only.

I attempted to correct by closing the workbook before opening; however, that was not successful.

Please advise as the debug feature highlights, “xlBook.Save”.

Private Sub WrkBKPages_Click()
Dim xlApp As Object
Dim xlBook As Object
Dim xlSheet As Object
Dim varCentreFooter As String
Dim rs As Recordset
Dim SSTab As String
Dim shtName As String
Dim ws As Worksheet
Set xlApp = CreateObject("Excel.Application")
DoCmd.Hourglass True
Set rs = CurrentDb.OpenRecordset("TblReports")
rs.MoveFirst

xlApp.DisplayAlerts = False
'Set reference to Workbook object
xlApp.EnableEvents = False
'Call xlApp.Workbooks("H:\MasterReport.xls").Close
Set xlBook = xlApp.Workbooks.Open("H:\MasterReport.xls")  'S:\Finance\Finance Shared\CFIDIR\ANALYSIS\Close Reports\MasterReport.xls

For Each ws In ActiveWorkbook.Worksheets

ws.PageSetup.CenterFooter = "Page # &P"

Next

    xlBook.Save
    xlBook.Close SaveChanges:=True
    xlApp.Quit
    Set xlSheet = Nothing
    Set xlBook = Nothing
    Set xlApp = Nothing
 
 DoCmd.Hourglass False
MsgBox "The Workbook has Page Numbers!"

End Sub
0
Comment
Question by:CFMI
2 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 39238822
Which line does the debugger jump to, and can you post a screen shot of the actual error message?

I just tried running code that updates the footer in a read-only workbook, and it runs successfully.

If you have a read-only workbook, you should probably be using SaveAs rather than Save.  I would also change "For Each ws In ActiveWorkbook.Worksheets" to "For Each ws In xlBook.Worksheets".
0
 
LVL 1

Author Closing Comment

by:CFMI
ID: 39238912
The provided statement worked well and page numbers were included.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question