Problem with updating Excel from Access -

Amileaux

Board Regular
Joined
Nov 3, 2002
Messages
110
I have an excel template that uses a query tied to access to update data. (Data/Import External Data/New Database Query). Usually I have to open up excel and manually update the worksheet before emailing off. So I decided to try and automate it. Below is my code, everything works fine until the "Selection.QueryTable.Refresh BackgroundQuery:=False" row.
I get the message "Object variable or With Block Variable not set". I am setting the the worksheet to work from. (I got the code by recording a macro in excel when I do the "manual" update.) Any thoughts would be appreciated. Thank you. Marie

Private Sub cmdVDSLFTTH_Click()
'On Error GoTo Err_cmdVDSLFTTH_Click
Dim I As Integer
Dim xlapp As Excel.Application
Dim wkbTemplate As Excel.Workbook
Dim wksRpt As Excel.Worksheet
Dim wksFTTH As Excel.Worksheet
Dim wksVDSL As Excel.Worksheet
'Set Object references in Excel
Set wkbTemplate = GetObject(strfilepath & "VDSLFTTH.xlt")
Set xlapp = wkbTemplate.Parent
Set wksRpt = wkbTemplate.Worksheets("DataSheet")
Set wksFTTH = wkbTemplate.Worksheets("FTTH")
Set wksVDSL = wkbTemplate.Worksheets("VDSL")
xlapp.Visible = True
wkbTemplate.Windows(1).Visible = True
wksRpt.Range("A2").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Marie

Which line causes the error?
 
Upvote 0
I've resolved this now. Should have been


wksRpt.Range("A2").QueryTable.Refresh BackgroundQuery:=False

Marie
 
Upvote 0

Forum statistics

Threads
1,207,012
Messages
6,076,148
Members
446,187
Latest member
LMill

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