Object variable or With block variable not set error for multiple report based on a template

karimsrouji

New Member
Joined
Jan 22, 2013
Messages
2
Hello,

I am trying to generate Report using a predefined template. I select the reports i want from a listbox then run the macro. The first report generates successfully; however the second report will cause an error: "Object variable or With block variable not set " when calling a table from the bookmark. The bookmark is selected successfully but can't select the table.

wdDoc.Bookmarks("BusinessScenarioAct").Select
Set tbl = Selection.Tables(1) (Error is Here)
wdDoc.Bookmarks("BusinessScenarioRisk").Select
Set tbl1 = Selection.Tables(1) (Error is Here)
wdDoc.Bookmarks("BusinessScenarioScreen").Select
Set tbl2 = Selection.Tables(1) (Error is Here)

Thanks
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hmmm, assuming that the bookmarks you included all contain tables, I can't see anything wrong with the code. Just double check that:

1. You've named your bookmarks correctly in the code; and
2. You've correctly declared your variables.

That's all I can say - perhaps if you could post your entire code, we could give more advice.

Thanks
 
Upvote 0
Welcome to MrExcel.

Assuming you are automating Word from Excel, instead of:

Rich (BB code):
wdDoc.Bookmarks("BusinessScenarioAct").Select
Set tbl = Selection.Tables(1)

try:

Rich (BB code):
Set tbl = wdDoc.Bookmarks("BusinessScenarioAct").Tables(1)

If you must use Selection you need to qualify it with the Word Application, but you haven't said what that is. Maybe:

Rich (BB code):
Set tbl = wdApp.Selection.Tables(1)
 
Upvote 0
It worked!
Thanks a lot! :)


Welcome to MrExcel.

Assuming you are automating Word from Excel, instead of:

Rich (BB code):
wdDoc.Bookmarks("BusinessScenarioAct").Select
Set tbl = Selection.Tables(1)

try:

Rich (BB code):
Set tbl = wdDoc.Bookmarks("BusinessScenarioAct").Tables(1)

If you must use Selection you need to qualify it with the Word Application, but you haven't said what that is. Maybe:

Rich (BB code):
Set tbl = wdApp.Selection.Tables(1)
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,198
Members
449,072
Latest member
DW Draft

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