Solved

Error when using an array for PublishObjects.Add

Posted on 2004-09-29
10
1,354 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
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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

770 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