msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Calling a Excel function from VB
Goto page 1, 2  Next
 
Post new topic   Reply to topic    msvisual.com Forum Index -> VB General Discussions
Author Message
SAL



Joined: 25 Feb 2008
Posts: 8

PostPosted: Mon Feb 25, 2008 6:30 pm    Post subject: Calling a Excel function from VB Reply with quote

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?

SAL

Archived from group: microsoft>public>vb>general>discussion
Back to top
View user's profile Send private message
Ralph



Joined: 04 Oct 2007
Posts: 4148

PostPosted: Mon Feb 25, 2008 8:58 pm    Post subject: Re: Calling a Excel function from VB Reply with quote

"SAL" wrote in message$dIHA.3400@TK2MSFTNGP03.phx.gbl...
> 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.


You should post to an Excel newsgroup for exact details. My guess is that
the Worksheet or Excel Project is "protected".

In Excel open the VB Editor. Select Tools:: Properties ->
Protection Tab - Lock checkbox. I would assume that if it is 'protected'
then you will not get that far as you will be asked for a password.

But best to check in an Excel group.

-ralph
Back to top
View user's profile Send private message
RB Smissaert



Joined: 04 Oct 2007
Posts: 865

PostPosted: Tue Feb 26, 2008 3:43 am    Post subject: Re: Calling a Excel function from VB Reply with quote

What is missing from your posted code is the variable declarations.
There are some odd things in the code eg:
Set MyXlSheet = myXL.Workbooks.Open

Also:
MyXlSheet.Application.Run etc.
Shouldn't this be:
MyXl.Run etc.

Also it is better to fully qualify the procedure to run:
oXL.Run "Workbook1.xls!modMain.Proc1", arg1

RBS


"SAL" wrote in message $dIHA.3400@TK2MSFTNGP03.phx.gbl...
> 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?
>
> SAL
>
Back to top
View user's profile Send private message
SAL



Joined: 25 Feb 2008
Posts: 8

PostPosted: Mon Feb 25, 2008 8:30 pm    Post subject: Re: Calling a Excel function from VB Reply with quote

Sorry RB, following are my variable declares:

Dim MyXlSheet As Workbook
Dim myXL As Excel.Application

I tried fully qualifying the procedure and it didn't make any difference.
So, I tried the following code:

MyXlSheet.Application.Run "FullProperty.xsl!CopyComps", 2,
m_XArray.UpperBound(2) - 3

And
MyXlSheet.Application.Run "FullProperty.xsl!Module!CopyComps", 2,
m_XArray.UpperBound(2) - 3

CopyComps is in the module for the FullProperty sheet.
I also get the same error if I try to run it with the myXL object... Sad

SAL


"RB Smissaert" wrote in message
news:%23r%23$J$$dIHA.1376@TK2MSFTNGP02.phx.gbl...
> What is missing from your posted code is the variable declarations.
> There are some odd things in the code eg:
> Set MyXlSheet = myXL.Workbooks.Open
>
> Also:
> MyXlSheet.Application.Run etc.
> Shouldn't this be:
> MyXl.Run etc.
>
> Also it is better to fully qualify the procedure to run:
> oXL.Run "Workbook1.xls!modMain.Proc1", arg1
>
> RBS
>
>
> "SAL" wrote in message
> $dIHA.3400@TK2MSFTNGP03.phx.gbl...
>> 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?
>>
>> SAL
>>
>
Back to top
View user's profile Send private message
RB Smissaert



Joined: 04 Oct 2007
Posts: 865

PostPosted: Tue Feb 26, 2008 4:45 am    Post subject: Re: Calling a Excel function from VB Reply with quote

> FullProperty.xsl

Is this your code? If so then changing it to FullProperty.xls may help.

It doesn' really alter anything but doing Dim MyXlSheet As Workbook will
cause confusion
and I would do something like Dim oWB As Workbook

Also try Dim myXL As Object

RBS


"SAL" wrote in message @TK2MSFTNGP03.phx.gbl...
> Sorry RB, following are my variable declares:
>
> Dim MyXlSheet As Workbook
> Dim myXL As Excel.Application
>
> I tried fully qualifying the procedure and it didn't make any difference.
> So, I tried the following code:
>
> MyXlSheet.Application.Run "FullProperty.xsl!CopyComps", 2,
> m_XArray.UpperBound(2) - 3
>
> And
> MyXlSheet.Application.Run "FullProperty.xsl!Module!CopyComps", 2,
> m_XArray.UpperBound(2) - 3
>
> CopyComps is in the module for the FullProperty sheet.
> I also get the same error if I try to run it with the myXL object... Sad
>
> SAL
>
>
> "RB Smissaert" wrote in message
> news:%23r%23$J$$dIHA.1376@TK2MSFTNGP02.phx.gbl...
>> What is missing from your posted code is the variable declarations.
>> There are some odd things in the code eg:
>> Set MyXlSheet = myXL.Workbooks.Open
>>
>> Also:
>> MyXlSheet.Application.Run etc.
>> Shouldn't this be:
>> MyXl.Run etc.
>>
>> Also it is better to fully qualify the procedure to run:
>> oXL.Run "Workbook1.xls!modMain.Proc1", arg1
>>
>> RBS
>>
>>
>> "SAL" wrote in message
>> $dIHA.3400@TK2MSFTNGP03.phx.gbl...
>>> 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?
>>>
>>> SAL
>>>
>>
>
>
Back to top
View user's profile Send private message
SAL



Joined: 25 Feb 2008
Posts: 8

PostPosted: Mon Feb 25, 2008 9:00 pm    Post subject: Re: Calling a Excel function from VB Reply with quote

Opps, that was just a typo in this message. It does say xls in the code.


"RB Smissaert" wrote in message @TK2MSFTNGP04.phx.gbl...
>> FullProperty.xsl
>
> Is this your code? If so then changing it to FullProperty.xls may help.
>
> It doesn' really alter anything but doing Dim MyXlSheet As Workbook will
> cause confusion
> and I would do something like Dim oWB As Workbook
>
> Also try Dim myXL As Object
>
> RBS
>
>
> "SAL" wrote in message
> @TK2MSFTNGP03.phx.gbl...
>> Sorry RB, following are my variable declares:
>>
>> Dim MyXlSheet As Workbook
>> Dim myXL As Excel.Application
>>
>> I tried fully qualifying the procedure and it didn't make any difference.
>> So, I tried the following code:
>>
>> MyXlSheet.Application.Run "FullProperty.xsl!CopyComps", 2,
>> m_XArray.UpperBound(2) - 3
>>
>> And
>> MyXlSheet.Application.Run "FullProperty.xsl!Module!CopyComps", 2,
>> m_XArray.UpperBound(2) - 3
>>
>> CopyComps is in the module for the FullProperty sheet.
>> I also get the same error if I try to run it with the myXL object... Sad
>>
>> SAL
>>
>>
>> "RB Smissaert" wrote in message
>> news:%23r%23$J$$dIHA.1376@TK2MSFTNGP02.phx.gbl...
>>> What is missing from your posted code is the variable declarations.
>>> There are some odd things in the code eg:
>>> Set MyXlSheet = myXL.Workbooks.Open
>>>
>>> Also:
>>> MyXlSheet.Application.Run etc.
>>> Shouldn't this be:
>>> MyXl.Run etc.
>>>
>>> Also it is better to fully qualify the procedure to run:
>>> oXL.Run "Workbook1.xls!modMain.Proc1", arg1
>>>
>>> RBS
>>>
>>>
>>> "SAL" wrote in message
>>> $dIHA.3400@TK2MSFTNGP03.phx.gbl...
>>>> 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?
>>>>
>>>> SAL
>>>>
>>>
>>
>>
>
Back to top
View user's profile Send private message
Karl E. Peterson



Joined: 04 Oct 2007
Posts: 4836

PostPosted: Mon Feb 25, 2008 9:26 pm    Post subject: Re: Calling a Excel function from VB Reply with quote

SAL wrote:
> Opps, that was just a typo in this message. It does say xls in the code.

Major problem! WTH are you *typing* code into a forum post that seeks help
determining why the code "doesn't work"? You're just wasting people's time, here.
--
..NET: It's About Trust!
http://vfred.mvps.org
Back to top
View user's profile Send private message
Robert Morley



Joined: 22 Dec 2007
Posts: 176

PostPosted: Tue Feb 26, 2008 2:07 am    Post subject: Re: Calling a Excel function from VB Reply with quote

Ummm...did somebody piss in your corn flakes this morning Karl?


Rob

Karl E. Peterson wrote:
> SAL wrote:
>> Opps, that was just a typo in this message. It does say xls in the code.
>
> Major problem! WTH are you *typing* code into a forum post that seeks help
> determining why the code "doesn't work"? You're just wasting people's time, here.
Back to top
View user's profile Send private message
Karl E. Peterson



Joined: 04 Oct 2007
Posts: 4836

PostPosted: Mon Feb 25, 2008 11:27 pm    Post subject: Re: Calling a Excel function from VB Reply with quote

Robert Morley wrote:
> Karl E. Peterson wrote:
>> SAL wrote:
>>> Opps, that was just a typo in this message. It does say xls in the code.
>>
>> Major problem! WTH are you *typing* code into a forum post that seeks help
>> determining why the code "doesn't work"? You're just wasting people's time,
>> here.
>
> Ummm...did somebody piss in your corn flakes this morning Karl?

Hasn't been the best of days, ya got me there. But(!), I stand by the position that
code should never be retyped into a forum post. Far, far too many times I've seen
good people spin their wheels in that situation.
--
..NET: It's About Trust!
http://vfred.mvps.org
Back to top
View user's profile Send private message
Steve Gerrard



Joined: 04 Oct 2007
Posts: 1164

PostPosted: Mon Feb 25, 2008 11:57 pm    Post subject: Re: Calling a Excel function from VB Reply with quote

SAL wrote:
> Opps, that was just a typo in this message. It does say xls in the
> code.
>

Copy/Paste the code.

Check macro security settings in Excel.

Is there more than one workbook open in Excel?
Back to top
View user's profile Send private message
Robert Morley



Joined: 22 Dec 2007
Posts: 176

PostPosted: Tue Feb 26, 2008 3:12 am    Post subject: Re: Calling a Excel function from VB Reply with quote

Agreed, absolutely!

Karl E. Peterson wrote:
> Robert Morley wrote:
>> Karl E. Peterson wrote:
>>> SAL wrote:
>>>> Opps, that was just a typo in this message. It does say xls in the code.
>>> Major problem! WTH are you *typing* code into a forum post that seeks help
>>> determining why the code "doesn't work"? You're just wasting people's time,
>>> here.
>> Ummm...did somebody piss in your corn flakes this morning Karl?
>
> Hasn't been the best of days, ya got me there. But(!), I stand by the position that
> code should never be retyped into a forum post. Far, far too many times I've seen
> good people spin their wheels in that situation.
Back to top
View user's profile Send private message
Jialiang Ge [MSFT]



Joined: 15 Nov 2007
Posts: 4

PostPosted: Tue Feb 26, 2008 11:23 am    Post subject: RE: Calling a Excel function from VB Reply with quote

Hello SAL,

From your post, my understanding on this issue is: you wonder how to fix
the issue 1004 (The macro cannot be found) in the VB client that
automates/calls an Excel macro. If I'm off base, please feel free to let me
know.

I have tested the code in your first message, and it works well on my side.
So I think the error might be caused by some configuration issues. Below I
list the points I can think of at the moment. Please have a look and let me
know if it helps.

1. The method "CopyComps" should be in a Module of the workbook.
If the method is in a sheet (Double click a sheet (e.g. Sheet1) in the
workbook's VBE view (Alt + F11), and copy & paste the method into it), the
error "1004 The macro 'CopyComps' cannot be found" will be thrown. We
should put the "CopyComps" in a module (Right click the workbook's VBA
project in VBE view, choose Insert->Module, and copy & paste the method
into it)

2. List all the macros from the workbook and see if "CopyComps" is in the
list.
Step A. make sure that VB6 Menu->Project->Preferences, "Microsoft Visual
Basic for Applications Extensibility" is checked.
Step B. Copy & Paste the following VB code right below the call of
"MyXlSheet.Application.Visible = True". It will MsgBox the macro name when
it finds a macro.

Dim N&, Count&, MyList(200), List$
For Each Component In MyXlSheet.VBProject.VBComponents
With Component.CodeModule
Count = .CountOfDeclarationLines + 1
Do Until Count >= .CountOfLines
MyList(N) = .ProcOfLine(Count, _
vbext_pk_Proc)
Count = Count + .ProcCountLines _
(.ProcOfLine(Count, vbext_pk_Proc), _
vbext_pk_Proc)
MsgBox MyList(N)
List = List & vbCr & MyList(N)
If Count < .CountOfLines Then N = N + 1
Loop
End With
N = N + 1
Next

3. Try to see if we can call the macro with fully qualified procedure name.
This has been mentioned by RB, but I notice some problem when you tried the
suggestion.
"MyXlSheet.Application.Run "FullProperty.xsl!CopyComps", 2,
m_XArray.UpperBound(2) - 3"

Problem 1: there seems to be a typo in the line. FullProperty.xsl ->
FullProperty.xls
Problem 2: The fully qualified name should be
FullProperty.xls!Module1.CopyComps, where Module1 is the name of the module
where CopyComps is located. Please change it to the exact name on your
side. In addition, it should be a dot ('.'), rather than a bang ('!')
following the module name.

4. According to the declaration of the MyXlSheet declaration (Dim MyXlSheet
As Workbook), I think you are using early binding (explicitly reference the
Microsoft Excel Object Library). Please make sure that the version of Excel
object model reference by the project is exactly the same as the Office
product version installed on the running machine. For instance, Microsoft
Excel Object Library 11.0 stands for Microsoft Excel 2003.

5. We do not have the code of DoEvents and ReadyExcel which is mentioned in
the first message. If you doubt that the error may be caused by the two
methods, please paste their codes here and we will check them for you.

6. If the points above do not help, is it possible for you to send a small
and reproducible sample to my mailbox (jialge@microsoft.com)? I will check
if it can run on my computer and determine if it is caused by an
environment issue.

Hope it helps.
If you have any other concerns, please feel free to let us know.

Regards,
Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Back to top
View user's profile Send private message
SAL



Joined: 25 Feb 2008
Posts: 8

PostPosted: Tue Feb 26, 2008 5:14 pm    Post subject: Re: Calling a Excel function from VB Reply with quote

Jialiang Ge,
this application is distributed to many desktops in our company. They are
all still working, just not on my pc (the developement pc). That implies
that something has changed on my pc (perhaps by IT), but I can't figure out
what. I tried many of the suggestions in your e-mail to no avail. I still
get the same error.
What else could be causing this? BTW, there's a case statement in the
procedure which opens a different spreadsheet file for each SELECT CASE. The
others are still working. I copied and pasted the code to a public Module,
as suggested, fully qualified it and still the same error.

SAL

"Jialiang Ge [MSFT]" wrote in message @TK2MSFTNGHUB02.phx.gbl...
> Hello SAL,
>
> From your post, my understanding on this issue is: you wonder how to fix
> the issue 1004 (The macro cannot be found) in the VB client that
> automates/calls an Excel macro. If I'm off base, please feel free to let
> me
> know.
>
> I have tested the code in your first message, and it works well on my
> side.
> So I think the error might be caused by some configuration issues. Below I
> list the points I can think of at the moment. Please have a look and let
> me
> know if it helps.
>
> 1. The method "CopyComps" should be in a Module of the workbook.
> If the method is in a sheet (Double click a sheet (e.g. Sheet1) in the
> workbook's VBE view (Alt + F11), and copy & paste the method into it), the
> error "1004 The macro 'CopyComps' cannot be found" will be thrown. We
> should put the "CopyComps" in a module (Right click the workbook's VBA
> project in VBE view, choose Insert->Module, and copy & paste the method
> into it)
>
> 2. List all the macros from the workbook and see if "CopyComps" is in the
> list.
> Step A. make sure that VB6 Menu->Project->Preferences, "Microsoft Visual
> Basic for Applications Extensibility" is checked.
> Step B. Copy & Paste the following VB code right below the call of
> "MyXlSheet.Application.Visible = True". It will MsgBox the macro name when
> it finds a macro.
>
> Dim N&, Count&, MyList(200), List$
> For Each Component In MyXlSheet.VBProject.VBComponents
> With Component.CodeModule
> Count = .CountOfDeclarationLines + 1
> Do Until Count >= .CountOfLines
> MyList(N) = .ProcOfLine(Count, _
> vbext_pk_Proc)
> Count = Count + .ProcCountLines _
> (.ProcOfLine(Count, vbext_pk_Proc), _
> vbext_pk_Proc)
> MsgBox MyList(N)
> List = List & vbCr & MyList(N)
> If Count < .CountOfLines Then N = N + 1
> Loop
> End With
> N = N + 1
> Next
>
> 3. Try to see if we can call the macro with fully qualified procedure
> name.
> This has been mentioned by RB, but I notice some problem when you tried
> the
> suggestion.
> "MyXlSheet.Application.Run "FullProperty.xsl!CopyComps", 2,
> m_XArray.UpperBound(2) - 3"
>
> Problem 1: there seems to be a typo in the line. FullProperty.xsl ->
> FullProperty.xls
> Problem 2: The fully qualified name should be
> FullProperty.xls!Module1.CopyComps, where Module1 is the name of the
> module
> where CopyComps is located. Please change it to the exact name on your
> side. In addition, it should be a dot ('.'), rather than a bang ('!')
> following the module name.
>
> 4. According to the declaration of the MyXlSheet declaration (Dim
> MyXlSheet
> As Workbook), I think you are using early binding (explicitly reference
> the
> Microsoft Excel Object Library). Please make sure that the version of
> Excel
> object model reference by the project is exactly the same as the Office
> product version installed on the running machine. For instance, Microsoft
> Excel Object Library 11.0 stands for Microsoft Excel 2003.
>
> 5. We do not have the code of DoEvents and ReadyExcel which is mentioned
> in
> the first message. If you doubt that the error may be caused by the two
> methods, please paste their codes here and we will check them for you.
>
> 6. If the points above do not help, is it possible for you to send a small
> and reproducible sample to my mailbox (jialge@microsoft.com)? I will check
> if it can run on my computer and determine if it is caused by an
> environment issue.
>
> Hope it helps.
> If you have any other concerns, please feel free to let us know.
>
> Regards,
> Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
> Microsoft Online Community Support
>
> ==================================================
> For MSDN subscribers whose posts are left unanswered, please check this
> document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx
>
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> ications. If you are using Outlook Express/Windows Mail, please make sure
> you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
> see your reply promptly.
>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/default.aspx.
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
>
Back to top
View user's profile Send private message
RB Smissaert



Joined: 04 Oct 2007
Posts: 865

PostPosted: Wed Feb 27, 2008 1:26 am    Post subject: Re: Calling a Excel function from VB Reply with quote

Does it work when there is no other workbook open at all?
So, no other .xls, no .xla, no Personal.xls, just only that particular WB.

RBS


"SAL" wrote in message
news:%23s9ZiQLeIHA.4728@TK2MSFTNGP03.phx.gbl...
> Jialiang Ge,
> this application is distributed to many desktops in our company. They are
> all still working, just not on my pc (the developement pc). That implies
> that something has changed on my pc (perhaps by IT), but I can't figure
> out what. I tried many of the suggestions in your e-mail to no avail. I
> still get the same error.
> What else could be causing this? BTW, there's a case statement in the
> procedure which opens a different spreadsheet file for each SELECT CASE.
> The others are still working. I copied and pasted the code to a public
> Module, as suggested, fully qualified it and still the same error.
>
> SAL
>
> "Jialiang Ge [MSFT]" wrote in message
> @TK2MSFTNGHUB02.phx.gbl...
>> Hello SAL,
>>
>> From your post, my understanding on this issue is: you wonder how to fix
>> the issue 1004 (The macro cannot be found) in the VB client that
>> automates/calls an Excel macro. If I'm off base, please feel free to let
>> me
>> know.
>>
>> I have tested the code in your first message, and it works well on my
>> side.
>> So I think the error might be caused by some configuration issues. Below
>> I
>> list the points I can think of at the moment. Please have a look and let
>> me
>> know if it helps.
>>
>> 1. The method "CopyComps" should be in a Module of the workbook.
>> If the method is in a sheet (Double click a sheet (e.g. Sheet1) in the
>> workbook's VBE view (Alt + F11), and copy & paste the method into it),
>> the
>> error "1004 The macro 'CopyComps' cannot be found" will be thrown. We
>> should put the "CopyComps" in a module (Right click the workbook's VBA
>> project in VBE view, choose Insert->Module, and copy & paste the method
>> into it)
>>
>> 2. List all the macros from the workbook and see if "CopyComps" is in the
>> list.
>> Step A. make sure that VB6 Menu->Project->Preferences, "Microsoft Visual
>> Basic for Applications Extensibility" is checked.
>> Step B. Copy & Paste the following VB code right below the call of
>> "MyXlSheet.Application.Visible = True". It will MsgBox the macro name
>> when
>> it finds a macro.
>>
>> Dim N&, Count&, MyList(200), List$
>> For Each Component In MyXlSheet.VBProject.VBComponents
>> With Component.CodeModule
>> Count = .CountOfDeclarationLines + 1
>> Do Until Count >= .CountOfLines
>> MyList(N) = .ProcOfLine(Count, _
>> vbext_pk_Proc)
>> Count = Count + .ProcCountLines _
>> (.ProcOfLine(Count, vbext_pk_Proc), _
>> vbext_pk_Proc)
>> MsgBox MyList(N)
>> List = List & vbCr & MyList(N)
>> If Count < .CountOfLines Then N = N + 1
>> Loop
>> End With
>> N = N + 1
>> Next
>>
>> 3. Try to see if we can call the macro with fully qualified procedure
>> name.
>> This has been mentioned by RB, but I notice some problem when you tried
>> the
>> suggestion.
>> "MyXlSheet.Application.Run "FullProperty.xsl!CopyComps", 2,
>> m_XArray.UpperBound(2) - 3"
>>
>> Problem 1: there seems to be a typo in the line. FullProperty.xsl ->
>> FullProperty.xls
>> Problem 2: The fully qualified name should be
>> FullProperty.xls!Module1.CopyComps, where Module1 is the name of the
>> module
>> where CopyComps is located. Please change it to the exact name on your
>> side. In addition, it should be a dot ('.'), rather than a bang ('!')
>> following the module name.
>>
>> 4. According to the declaration of the MyXlSheet declaration (Dim
>> MyXlSheet
>> As Workbook), I think you are using early binding (explicitly reference
>> the
>> Microsoft Excel Object Library). Please make sure that the version of
>> Excel
>> object model reference by the project is exactly the same as the Office
>> product version installed on the running machine. For instance, Microsoft
>> Excel Object Library 11.0 stands for Microsoft Excel 2003.
>>
>> 5. We do not have the code of DoEvents and ReadyExcel which is mentioned
>> in
>> the first message. If you doubt that the error may be caused by the two
>> methods, please paste their codes here and we will check them for you.
>>
>> 6. If the points above do not help, is it possible for you to send a
>> small
>> and reproducible sample to my mailbox (jialge@microsoft.com)? I will
>> check
>> if it can run on my computer and determine if it is caused by an
>> environment issue.
>>
>> Hope it helps.
>> If you have any other concerns, please feel free to let us know.
>>
>> Regards,
>> Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
>> Microsoft Online Community Support
>>
>> ==================================================
>> For MSDN subscribers whose posts are left unanswered, please check this
>> document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx
>>
>> Get notification to my posts through email? Please refer to
>> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
>> ications. If you are using Outlook Express/Windows Mail, please make sure
>> you clear the check box "Tools/Options/Read: Get 300 headers at a time"
>> to
>> see your reply promptly.
>>
>> Note: The MSDN Managed Newsgroup support offering is for non-urgent
>> issues
>> where an initial response from the community or a Microsoft Support
>> Engineer within 1 business day is acceptable. Please note that each
>> follow
>> up response may take approximately 2 business days as the support
>> professional working with you may need further investigation to reach the
>> most efficient resolution. The offering is not appropriate for situations
>> that require urgent, real-time or phone-based interactions or complex
>> project analysis and dump analysis issues. Issues of this nature are best
>> handled working with a dedicated Microsoft Support Engineer by contacting
>> Microsoft Customer Support Services (CSS) at
>> http://msdn.microsoft.com/subscriptions/support/default.aspx.
>> ==================================================
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>>
>>
>
>
Back to top
View user's profile Send private message
SAL



Joined: 25 Feb 2008
Posts: 8

PostPosted: Tue Feb 26, 2008 8:14 pm    Post subject: Re: Calling a Excel function from VB Reply with quote

Unfortunately not. I just tried it executing one of the other Case
statements prior this the problematic one and still the same error. Grrrr!

SAL

"RB Smissaert" wrote in message @TK2MSFTNGP05.phx.gbl...
> Does it work when there is no other workbook open at all?
> So, no other .xls, no .xla, no Personal.xls, just only that particular WB.
>
> RBS
>
>
> "SAL" wrote in message
> news:%23s9ZiQLeIHA.4728@TK2MSFTNGP03.phx.gbl...
>> Jialiang Ge,
>> this application is distributed to many desktops in our company. They are
>> all still working, just not on my pc (the developement pc). That implies
>> that something has changed on my pc (perhaps by IT), but I can't figure
>> out what. I tried many of the suggestions in your e-mail to no avail. I
>> still get the same error.
>> What else could be causing this? BTW, there's a case statement in the
>> procedure which opens a different spreadsheet file for each SELECT CASE.
>> The others are still working. I copied and pasted the code to a public
>> Module, as suggested, fully qualified it and still the same error.
>>
>> SAL
>>
>> "Jialiang Ge [MSFT]" wrote in message
>> @TK2MSFTNGHUB02.phx.gbl...
>>> Hello SAL,
>>>
>>> From your post, my understanding on this issue is: you wonder how to fix
>>> the issue 1004 (The macro cannot be found) in the VB client that
>>> automates/calls an Excel macro. If I'm off base, please feel free to let
>>> me
>>> know.
>>>
>>> I have tested the code in your first message, and it works well on my
>>> side.
>>> So I think the error might be caused by some configuration issues. Below
>>> I
>>> list the points I can think of at the moment. Please have a look and let
>>> me
>>> know if it helps.
>>>
>>> 1. The method "CopyComps" should be in a Module of the workbook.
>>> If the method is in a sheet (Double click a sheet (e.g. Sheet1) in the
>>> workbook's VBE view (Alt + F11), and copy & paste the method into it),
>>> the
>>> error "1004 The macro 'CopyComps' cannot be found" will be thrown. We
>>> should put the "CopyComps" in a module (Right click the workbook's VBA
>>> project in VBE view, choose Insert->Module, and copy & paste the method
>>> into it)
>>>
>>> 2. List all the macros from the workbook and see if "CopyComps" is in
>>> the
>>> list.
>>> Step A. make sure that VB6 Menu->Project->Preferences, "Microsoft Visual
>>> Basic for Applications Extensibility" is checked.
>>> Step B. Copy & Paste the following VB code right below the call of
>>> "MyXlSheet.Application.Visible = True". It will MsgBox the macro name
>>> when
>>> it finds a macro.
>>>
>>> Dim N&, Count&, MyList(200), List$
>>> For Each Component In MyXlSheet.VBProject.VBComponents
>>> With Component.CodeModule
>>> Count = .CountOfDeclarationLines + 1
>>> Do Until Count >= .CountOfLines
>>> MyList(N) = .ProcOfLine(Count, _
>>> vbext_pk_Proc)
>>> Count = Count + .ProcCountLines _
>>> (.ProcOfLine(Count, vbext_pk_Proc), _
>>> vbext_pk_Proc)
>>> MsgBox MyList(N)
>>> List = List & vbCr & MyList(N)
>>> If Count < .CountOfLines Then N = N + 1
>>> Loop
>>> End With
>>> N = N + 1
>>> Next
>>>
>>> 3. Try to see if we can call the macro with fully qualified procedure
>>> name.
>>> This has been mentioned by RB, but I notice some problem when you tried
>>> the
>>> suggestion.
>>> "MyXlSheet.Application.Run "FullProperty.xsl!CopyComps", 2,
>>> m_XArray.UpperBound(2) - 3"
>>>
>>> Problem 1: there seems to be a typo in the line. FullProperty.xsl ->
>>> FullProperty.xls
>>> Problem 2: The fully qualified name should be
>>> FullProperty.xls!Module1.CopyComps, where Module1 is the name of the
>>> module
>>> where CopyComps is located. Please change it to the exact name on your
>>> side. In addition, it should be a dot ('.'), rather than a bang ('!')
>>> following the module name.
>>>
>>> 4. According to the declaration of the MyXlSheet declaration (Dim
>>> MyXlSheet
>>> As Workbook), I think you are using early binding (explicitly reference
>>> the
>>> Microsoft Excel Object Library). Please make sure that the version of
>>> Excel
>>> object model reference by the project is exactly the same as the Office
>>> product version installed on the running machine. For instance,
>>> Microsoft
>>> Excel Object Library 11.0 stands for Microsoft Excel 2003.
>>>
>>> 5. We do not have the code of DoEvents and ReadyExcel which is mentioned
>>> in
>>> the first message. If you doubt that the error may be caused by the two
>>> methods, please paste their codes here and we will check them for you.
>>>
>>> 6. If the points above do not help, is it possible for you to send a
>>> small
>>> and reproducible sample to my mailbox (jialge@microsoft.com)? I will
>>> check
>>> if it can run on my computer and determine if it is caused by an
>>> environment issue.
>>>
>>> Hope it helps.
>>> If you have any other concerns, please feel free to let us know.
>>>
>>> Regards,
>>> Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
>>> Microsoft Online Community Support
>>>
>>> ==================================================
>>> For MSDN subscribers whose posts are left unanswered, please check this
>>> document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx
>>>
>>> Get notification to my posts through email? Please refer to
>>> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
>>> ications. If you are using Outlook Express/Windows Mail, please make
>>> sure
>>> you clear the check box "Tools/Options/Read: Get 300 headers at a time"
>>> to
>>> see your reply promptly.
>>>
>>> Note: The MSDN Managed Newsgroup support offering is for non-urgent
>>> issues
>>> where an initial response from the community or a Microsoft Support
>>> Engineer within 1 business day is acceptable. Please note that each
>>> follow
>>> up response may take approximately 2 business days as the support
>>> professional working with you may need further investigation to reach
>>> the
>>> most efficient resolution. The offering is not appropriate for
>>> situations
>>> that require urgent, real-time or phone-based interactions or complex
>>> project analysis and dump analysis issues. Issues of this nature are
>>> best
>>> handled working with a dedicated Microsoft Support Engineer by
>>> contacting
>>> Microsoft Customer Support Services (CSS) at
>>> http://msdn.microsoft.com/subscriptions/support/default.aspx.
>>> ==================================================
>>> This posting is provided "AS IS" with no warranties, and confers no
>>> rights.
>>>
>>>
>>
>>
>

Back to top
View user's profile Send private message
Display posts from previous:   
Related Topics:
Calling A Windows DLL Function From VBA/VB6 I have the following function in a standard Windows DLL (this is an example, not the real procedure) int __stdcall SumOf(int Arr[],int Num) { int N=0; int Sum=0; int X=0; for { X=Arr[N]; Sum+=X; } return Sum; } What is the proper Declare s

calling a window service function? Hi, is it possible to call a window service public service from a vb application and get the result? Thasnks.

Getting 'File Not Found' calling function in DLL from within Hi All, I have a strange problem that is relatively new, at least it never used to be a problem. I just do not know what changed. I have a VB6 based executable and application and a regular Win32 based DLL. I am using Microsoft Visual Studio.Net 2005 to m

Accessing System Date withOUT calling a WinAPI function OS: Win2000Pro SP3 app: VB6 SP3 I'd like my VB6 app to access the system date in a way not obvious to crackers poring over its executable i.e. a way that does NOT use an WinAPI function. I'm given to understand that while in-line assembly

Open Excel Template (Excel 2003) that contains macros with V Hi We have several excel templates (*.xlt) files with macros inside which get started by the user through a VB6 frontend. A few weeks ago we received an Office 2003 and XP SP2 upgrade. The VB tool and the Excel template still works but in the past the use
Post new topic   Reply to topic    msvisual.com Forum Index -> VB General Discussions All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group