Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / February 2008

Tip: Looking for answers? Try searching our database.

VB6 to excel question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SAL - 25 Feb 2008 22:18 GMT
Hello,
I hope this is the right place to post this question. I have a VB6
application that has been using automation to run code in Excel for years
and all of a sudden, it can't find the function in Excel that I'm calling.
I'm posting my code below but it's fairly straightforward. I could use a
little help on it.

        sToPath = App.Path & "\Excel\FullProperty.xls"
        bSuccess = CopyFile(sFromPath, sToPath)
        If bSuccess Then
           SetAttr sToPath, vbArchive
        End If

        Set myXL = GetObject(, "Excel.Application")

        If myXL Is Nothing Then
           Set myXL = CreateObject("Excel.Application")
        End If

        Set MyXlSheet = myXL.Workbooks.Open(FileName:=sToPath)

        MyXlSheet.Application.Visible = True
        DoEvents
        ReadyExcel

       ' The next line produces the Error:
       ' 1004 The macro 'CopyComps' cannot be found
        MyXlSheet.Application.Run "CopyComps", 2, m_XArray.UpperBound(2) -
3
        MyXlSheet.Application.Run "FillComps", m_vExcelArray

It could always find it before and I have verified that the routine is
definitely there.

Thoughts?  PS, the spreadsheet isn't protected.... :)

SAL
Jim Rech - 26 Feb 2008 14:34 GMT
When I run macros via automation I like to be explicit about the workbook
with the macro:

MyXL.Run MyXlSheet.Name & "!CopyComps", etc

Since MyXL is the Excel object no reason to add complexity:
MyXlSheet.Application

Signature

Jim

| Hello,
| I hope this is the right place to post this question. I have a VB6
[quoted text clipped - 33 lines]
|
| SAL
Bernie Deitrick - 26 Feb 2008 14:34 GMT
SAL,

Make sure that you don't have a named range or other object with the name CopyComps

Try explicity setting the path to the macro:

Dim str_Macro  As String
str_Macro = Thisworkbook.Name  &   "!CopyComps"
MyXlSheet.Application.Run str_Macro, 2, m_XArray.UpperBound(2) - 3

HTH,
Bernie
MS Excel MVP

> Hello,
> I hope this is the right place to post this question. I have a VB6
[quoted text clipped - 33 lines]
>
> SAL
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.