?
Solved

Error when using an array for PublishObjects.Add

Posted on 2004-09-29
10
Medium Priority
?
1,479 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Suggested Courses

649 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