Solved

Error when using an array for PublishObjects.Add

Posted on 2004-09-29
10
1,329 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
Comment Utility
Hope u r using above code in Excel VBA
0
 
LVL 10

Expert Comment

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

Author Comment

by:rmrq
Comment Utility
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
 
LVL 10

Expert Comment

by:anv
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:rmrq
Comment Utility
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
Comment Utility
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
Comment Utility
hi DanRollins

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

Author Comment

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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now