Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default VBA Extensibility problem

I have the following problem:

For some reason, seemingly at its whim, VBA inserts an extra line
containing only "()" after my code when i add code to a new module using

..CodeModule.AddFromString strCode

This only happens about 1/15 of the time, but it does so consistently.
I have checked the strCode, and there NEVER appears parentheses like
that anywhere. I also checked using debug.print strcode. But VBA
inserts the additional "()" line.

Any suggestions? Any help would be most appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default VBA Extensibility problem

Can you show us an example where the () is added.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"R Avery" wrote in message
...
I have the following problem:

For some reason, seemingly at its whim, VBA inserts an extra line
containing only "()" after my code when i add code to a new module using

.CodeModule.AddFromString strCode

This only happens about 1/15 of the time, but it does so consistently.
I have checked the strCode, and there NEVER appears parentheses like
that anywhere. I also checked using debug.print strcode. But VBA
inserts the additional "()" line.

Any suggestions? Any help would be most appreciated.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default VBA Extensibility problem

Actually, it seems to occur consistently when I declare this API
function. It has occurred elsewhere, and I will try to isolate what is
causing the extra "()". You can reproduce my problem on Excel 2002 with
the following code (assuming your project has Module1 with this code,
and blank Module2 and blank Module3).


Private Declare Function ShellExecute Lib "shell32" _
Alias "ShellExecuteA" _
(ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long



Private Sub CopyThisModuleCodeToOthers()
Dim strCode As String
Dim i As Long

With ThisWorkbook.VBProject.VBComponents
With .Item("Module1").CodeModule
strCode = .Lines(1, .CountOfLines)
End With

For i = 2 To 3
With .Item("Module" & i).CodeModule
.AddFromString strCode
End With
Next i
End With
End Sub
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default VBA Extensibility problem

Also, Registry API functions have had the same effect as the
ShellExecute function, in terms of inserting the "()" at the end of the
code.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default VBA Extensibility problem

I have discovered something interesting which suggest a bug in the facility.

Firstly, if you break the code before the 'AddFromString', strCode does not
have that ().

Also, if you move all of the first three lines of the API declaration to one
line, the problem goes away.

This suggests to me that the AddFromString sees the API declaration and is
looking for the () but doesn't see it, so adds it at the end.. If so, a
definite bug.

It is easily circumvented, but I like the layout that you show, and don't
like to have to lay it out to accommodate VB.


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"R Avery" wrote in message
...
Also, Registry API functions have had the same effect as the
ShellExecute function, in terms of inserting the "()" at the end of the
code.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default VBA Extensibility problem

The way I have dealt with it is to just iterate through every line of
the copied code if it contains any API declarations, looking for a line
with just "()" and delete any it finds.

Thanks for your help!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Colon at the end of excel file name(ex: problem.xls:1, problem.xls financeguy New Users to Excel 2 January 15th 10 01:15 AM
Started out as an Access problem. Now an Excel problem RobertM Excel Discussion (Misc queries) 2 April 26th 06 07:30 PM
VB Extensibility library and "late binding" Dennis Excel Discussion (Misc queries) 0 March 30th 05 10:51 PM
problem with a conditional max problem Brian Cornejo Excel Discussion (Misc queries) 1 February 18th 05 06:25 PM
Problem when multipple users access shared xl-file at the same time, macrocode for solve this problem? OCI Excel Programming 0 May 16th 04 10:40 PM


All times are GMT +1. The time now is 04:59 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"