Setting a workbook object with full path

DavidSCowan

Board Regular
Joined
Jun 7, 2009
Messages
78
Can someone help please.

I want to Set wkb as the workbook<TABLE style="WIDTH: 198pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=264><COLGROUP><COL style="WIDTH: 198pt; mso-width-source: userset; mso-width-alt: 8448" width=264><TBODY><TR style="HEIGHT: 12.75pt; mso-height-source: userset" height=17><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; WIDTH: 198pt; HEIGHT: 12.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" height=17 width=264>C:\Users\David\Documents\EasyXL\easy-xlIndex.xls

</TD></TR></TBODY></TABLE>
I thought that:
Dim wkb as workbook
Set wkb =workbooks("<TABLE style="WIDTH: 198pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=264><COLGROUP><COL style="WIDTH: 198pt; mso-width-source: userset; mso-width-alt: 8448" width=264><TBODY><TR style="HEIGHT: 12.75pt; mso-height-source: userset" height=17><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; WIDTH: 198pt; HEIGHT: 12.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" height=17 width=264>C:\Users\David\Documents\EasyXL\easy-xlIndex.xls")
would do the trick but it doesn't (and I have tried every variant I can think of)
</TD></TR></TBODY></TABLE>

What it produces is: "Run-time error '9'"; "Subscript out of range"
(I don't want to use ActiveWorkbook or ThisWorkBook)

Can someone help please.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi

SUCCESS AT LAST! :):)

After getting the very unhelpful error messages I took your advice and took it apart piece by piece. In the copy line I substituted the actual numbers e.g Cells(5,1) instead of Cells(finalrowi - 16, 1). When this was done it went through so the spotlight fell on the variables in that line. They were up the creak! I changed these and as suggested checked each one in the Immediate window. After spotting some other small errors the macro now works as intended.

I am really appreciative for all your help. In the past with the message board I have found that often what happens is that a completely different solution is suggested and I never find out what is wrong with mine and therefore there is no learning. And there is rarely any appetite for following through - the alternative solution is suggested and that is that - the caravan moves on - no replies to requests for clarification etc.. So I am doubly appreciative that you stayed on the case and sorted it out.

I have learnt a lot. And I have also started reading the Pearson reference.

Thanks again

David
 
Upvote 0
Good job!

You know that you can just hover the mouse over simple variables and see their values? Do take the time to read Chip Pearson's article for that and much more information.
 
Upvote 0
Chip Pearson's article is great - I will use all the things outlined from now on. And hovering is great too.

And it has already pinpointed a problem. To keep things simple part of the code was hard wired e.g. Cells(finalrowi - 16, 1). But it seems that some measures didn't exist in 2002 so when, for the first of these files, the procedure gets to this line finalrowi =1 and finalrowi - 16 goes negative!

Thanks again for all your patience.
 
Upvote 0
Thank you for asking but no not a question just reporting how the Chip Pearson article you suggested helped to track down the problem quickly.
 
Upvote 0
Excellent, well done.

Debugging your own code is the best way to get better.
 
Upvote 0

Forum statistics

Threads
1,216,113
Messages
6,128,907
Members
449,478
Latest member
Davenil

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