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

Hi.
I have a code which inserts some lines of code to new workbook..

Sub AddComboBoxCode2(VBCodeMod As CodeModule, sCodeName As String)
With VBCodeMod
.InsertLines .CountOfLines + 1, "Private Sub ComboBox1_Change()"
.InsertLines .CountOfLines + 1, " Dim TargetPivotTable As
PivotTable"
.InsertLines .CountOfLines + 1, " Dim units As String"
.InsertLines .CountOfLines + 1, " On Error GoTo ErrHandler"
.InsertLines .CountOfLines + 1, " Select Case ComboBox1.Value"

{...}


Everything works fine if VBA is open.
When I close VBA no code is added to workbook.


Did it happen to somebody?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Inserting VBA code...

Kris wrote:
Hi.
I have a code which inserts some lines of code to new workbook..

Sub AddComboBoxCode2(VBCodeMod As CodeModule, sCodeName As String)
With VBCodeMod
.InsertLines .CountOfLines + 1, "Private Sub ComboBox1_Change()"
.InsertLines .CountOfLines + 1, " Dim TargetPivotTable As
PivotTable"
.InsertLines .CountOfLines + 1, " Dim units As String"
.InsertLines .CountOfLines + 1, " On Error GoTo ErrHandler"
.InsertLines .CountOfLines + 1, " Select Case ComboBox1.Value"

{...}


Everything works fine if VBA is open.
When I close VBA no code is added to workbook.


Did it happen to somebody?



I found something.

..CodeName return empty string when vba is closed, and a name of sheet
when VBA is open.


So, next question.
Why .CodeName which is a actual value of parameter to function listed
above doesn't work with VBA closed.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Inserting VBA code...

You could force a recompile in your code with

Application.VBE.CommandBars.FindControl(ID:=578).E xecute


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Kris" wrote in message
...
Kris wrote:
Hi.
I have a code which inserts some lines of code to new workbook..

Sub AddComboBoxCode2(VBCodeMod As CodeModule, sCodeName As String)
With VBCodeMod
.InsertLines .CountOfLines + 1, "Private Sub ComboBox1_Change()"
.InsertLines .CountOfLines + 1, " Dim TargetPivotTable As
PivotTable"
.InsertLines .CountOfLines + 1, " Dim units As String"
.InsertLines .CountOfLines + 1, " On Error GoTo ErrHandler"
.InsertLines .CountOfLines + 1, " Select Case

ComboBox1.Value"

{...}


Everything works fine if VBA is open.
When I close VBA no code is added to workbook.


Did it happen to somebody?



I found something.

.CodeName return empty string when vba is closed, and a name of sheet
when VBA is open.


So, next question.
Why .CodeName which is a actual value of parameter to function listed
above doesn't work with VBA closed.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Inserting VBA code...

You could force a recompile in your code with

Application.VBE.CommandBars.FindControl(ID:=578).E xecute


That will fail if a compile is not required (the compile command
is grayed out). Instead, try

Dim Ctrl As Office.CommandBarControl
Set Ctrl = Application.VBE.CommandBars.FindControl(ID:=578)
If Ctrl.Enabled = True Then
Ctrl.Execute
End If

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Bob Phillips" wrote in
message ...
You could force a recompile in your code with

Application.VBE.CommandBars.FindControl(ID:=578).E xecute


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Kris" wrote in message
...
Kris wrote:
Hi.
I have a code which inserts some lines of code to new
workbook..

Sub AddComboBoxCode2(VBCodeMod As CodeModule, sCodeName As
String)
With VBCodeMod
.InsertLines .CountOfLines + 1, "Private Sub
ComboBox1_Change()"
.InsertLines .CountOfLines + 1, " Dim
TargetPivotTable As
PivotTable"
.InsertLines .CountOfLines + 1, " Dim units As
String"
.InsertLines .CountOfLines + 1, " On Error GoTo
ErrHandler"
.InsertLines .CountOfLines + 1, " Select Case

ComboBox1.Value"

{...}


Everything works fine if VBA is open.
When I close VBA no code is added to workbook.


Did it happen to somebody?



I found something.

.CodeName return empty string when vba is closed, and a name
of sheet
when VBA is open.


So, next question.
Why .CodeName which is a actual value of parameter to function
listed
above doesn't work with VBA closed.





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Inserting VBA code...

Kris wrote:

I found something.

.CodeName return empty string when vba is closed, and a name of sheet
when VBA is open.


So, next question.
Why .CodeName which is a actual value of parameter to function listed
above doesn't work with VBA closed.



I like to write to myself.

I found the problem.
CodeName property is not set if VBA is not open at least once.
it is done by design in Excel.


This lines of code solve the problem.

Dim vbp As Object
Set vbp = ActiveWorkbook.VBProject


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
inserting code into code module crashes Kris Excel Programming 8 January 25th 06 05:28 PM
Inserting a Code Alex Martins[_2_] Excel Programming 10 August 30th 05 12:20 AM
Inserting a Code Jim Thomlinson[_4_] Excel Programming 2 August 29th 05 09:50 PM
Inserting a Code Alex Martins[_2_] Excel Programming 2 August 29th 05 09:49 PM
Inserting a Code Jim Thomlinson[_4_] Excel Programming 0 August 29th 05 09:46 PM


All times are GMT +1. The time now is 05:30 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"