?
Solved

Error when using an array for PublishObjects.Add

Posted on 2004-09-29
10
Medium Priority
?
1,507 Views
Last Modified: 2012-08-14
This is probably something basic I'm overlooking, but I'm in a hurry!

I am trying to create HTML files (via macro) from Excel worksheets and would love to use the code below (from http://www.experts-exchange.com/Applications/MS_Office/Excel/Q_20924138.html).  I keep getting an error (Runtime Error '1004', Application-Defined or Object-Defined Error).  Is it something simple I'm overlooking?  Does 'sName' need to be declared as a particular variable?

----------------------------------------------------------------------

Public Sub CommandButton2_Click()

sName = Array("Executive Summary", "Electric")
For i = LBound(sName) To UBound(sName)
   
ActiveWorkbook.PublishObjects.Add(SourceType:=xlSourceSheet, Filename:="C:\" & sName(i) & ".htm", Sheet:=sName(i), HtmlType:=xlHtmlCalc).Publish
   
Next i

End Sub
---------------------------------------------------------------------

Thanks!
0
Comment
Question by:rmrq
  • 4
  • 4
8 Comments
 
LVL 10

Expert Comment

by:anv
ID: 12186904
Hope u r using above code in Excel VBA
0
 
LVL 10

Expert Comment

by:anv
ID: 12186908
moreover can u define the exact line where u r getting this error??
0
 

Author Comment

by:rmrq
ID: 12187171
Yes, using VBA 6.0, and the error is occurring on the following line:
ActiveWorkbook.PublishObjects.Add(SourceType:=xlSourceSheet, Filename:="C:\" & sName(i) & ".htm", Sheet:=sName(i),HtmlType:=xlHtmlCalc).Publish

Any ideas?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 10

Expert Comment

by:anv
ID: 12187198
please check if u have given valid references...

'coz i'm not getting any error on my pc..when used the above statement
..ActiveWorkbook.PublishObjects.Add(SourceType:=xlSourceSheet, Filename:="C:\" & sName(i) & ".htm", Sheet:=sName(i), HtmlType:=xlHtmlCalc).Publish

also check if Sheet SName(i) exists or not..
0
 

Author Comment

by:rmrq
ID: 12187251
The two sheets named in the sName(i) array do exist.  As far as references, I have no idea what I may be missing.... any ideas?  
0
 

Author Comment

by:rmrq
ID: 12187330
It must be a reference, because the code itself seems to work for many other people.....
0
 
LVL 10

Accepted Solution

by:
anv earned 750 total points
ID: 12621880
hi DanRollins

I feel The Points Shud awarded to me...
0
 

Author Comment

by:rmrq
ID: 12625043
The question was never answered, but Anv can have the points for attempting to.  I would delete it.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month16 days, 23 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question