Solved

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

Posted on 2013-06-11
2
518 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

919 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now