Updating Excel repots from MS Access using VBA

subhanak

Board Regular
Joined
Jul 9, 2005
Messages
75
Hi,
I am using the following sub to update a reporting metrics (MS Access/Excel). Currently, this sub refreshes the reports perfectly; however, I would like to modify it to add the following:
1. Save the workbook
2. Close it
3. Open password protected workbooks
Your suggestion and assistance is appreciated.
Thanks
=============================================================
Public Sub RefreshMatrics()
Dim ObjXL As Object, x
On Error Resume Next
Set ObjXL = CreateObject("Excel.Application")
With ObjXL.Application
.Visible = True
.workbooks.Open "Path..."
x = .ActiveWorkbook.refreshall
End With
Set ObjXL = Nothing
End Sub
=============================================================
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try this untested air code:
Code:
Dim xlx As Object, xlw As Object
Dim svChartPath As String
On Error GoTo ErrHandler....'first error handled from anything above should reset to zero if code is allowed to continue

svChartPath = DLookup(... I get info like this from a table
'more code?
On Error Resume Next  'redirect error handling until after test for Excel running already
Set xlApp = GetObject(, "Excel.Application") 'Bind to existing instance of Excel?
If Err.Numer<>0 Then 'Excel not running, create new instance
 On Error GoTo ErrHandler
 Set xlx = CreateObject("Excel.Application")
 xlx.Visible = False 'or true
 xlx.ScreenUpdating = False 'or true
 xlx.DisplayAlerts = False 'to stop prompt when saving altered file
 Set xlw = xlx.Workbooks.Open(svChartPath,,,,"Password")

 xlw.Save
 xlx.ScreenUpdating = True
 xlx.DisplayAlerts = True
 xlx.Quit
End If

ExitHere:
'clean up stuff
Set xlw = Nothing
Set xlx = Nothing

ErrHandler:
 
Upvote 0
Hi,
Thank you very much for your assistance.
xlx.DisplayAlerts = True/False is generating this error: Method or data member not found.

Do you know what I am missing? Please.

Thanks
 
Upvote 0
It can only be one or the other, not True/False. I do not see where I posted anything that looks like what you just posted.
 
Upvote 0
Sorry for the confusion, I meant

xlx.DisplayAlerts = True
xlx.DisplayAlerts = False

Generates this error: Method or data member not found.
 
Upvote 0
Hard to pin down without seeing all of the code. Please post what you have.
 
Upvote 0

Forum statistics

Threads
1,221,831
Messages
6,162,250
Members
451,757
Latest member
iours

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top