Solved

Error when using an array for PublishObjects.Add

Posted on 2004-09-29
10
1,408 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
10 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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 250 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

688 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