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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
64,624
Office Version
  1. 365
Platform
  1. Windows
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".
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
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.
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
It does seem to be a string. Maybe

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

would be better.
 

Forum statistics

Threads
1,171,274
Messages
5,874,783
Members
433,074
Latest member
alexbecker220

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
Top