Troubleshooting

kemperohlmeyer

Board Regular
Joined
Oct 4, 2006
Messages
73
For some reason this code worked perfectly yesterday, yet today i get an error stating "Object Variable or With Block Variable not set". When i try to debug it goes to the FileName = range("a18") line. Can someone help shed some light?

thanks,
ko

Dim FileName As Range
Dim c As Range

Sub SaveAsWebPage()
' A macro that saves the pre-defined area as a webpage
' By Kemper Ohlmeyer 10/5/2006

For Each c In Range("List3")
Range("A3").Value = c.Value
Calculate
FileName = Range("a18")
Range("A1:T44").Select
With ActiveWorkbook.PublishObjects("08 - Snapshot info - current managers_7205")
.HtmlType = xlHtmlStatic
.FileName = FileName
.Publish (False)
.AutoRepublish = False
End With
ChDir "P:\Portfolio Mgmt - Due Diligence\WG new\Coded Spreadsheet Templates\Snapshot"
Next c
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Two things I would recommend:

1. Unless you are declaring your variables publicly with the PUBLIC statement (which it appears you are not doing), declare your variables within the macro. So move the DIM statements inside your macro.

2. You should give variables names that are differently from any possible "reserved" words (words VBA uses for functions, methods, properties, etc). I don't know if "FileName" is a reserved word or not, but it very well could be. Try changing it to something like "MyFileName".
 
Upvote 0
To set a range reference you will also need to use the Set keyword:

Code:
Set myFileName = Range("A18")

Best regards

Richard

Having said that, I'm not actually sure why you are defining FileName (or myFileName when renamed) as a range - looks like it should be a string.
 
Upvote 0
It does seem to be a string. Maybe

Code:
 FileName = Range("a18").Value

would be better.
 
Upvote 0

Forum statistics

Threads
1,215,693
Messages
6,126,240
Members
449,304
Latest member
hagia_sofia

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