Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Copy VB code to other workbook?

Dear all,

I build the new workbooks from scratch and would like to
copy some VB code to the new workbook(s).

I am trying to copy the following code to the new workbook
("thisworkbook" module) as discussed and posted in "How to
write code to module" (03/04/03).

Private Sub Workbook_Activate()
Application.Run "TPBQ11.xls!CrMn"
End Sub

This is the sad attempt I made which does not work:

Sub test()
Application.VBE.MainWindow.Visible = False
Set TempModule = ActiveWorkbook.VBProject.VBComponents
("Thisworkbook")
strCode = "Private Sub Workbook_Activate()" & vbCr & _
"On Error Resume Next" & vbCr
& "Application.Run " & Chr(34) & "TPBQ11.xls!CrMn" & Chr
(34) & vbCr & _
"End Sub"
TempModule.CodeModule.AddFromString strCode
End Sub

I cannot find anything that explains how to do this and
cannot make the sample to wrk.

Any help would be really appreciated.

Kind reagards.

John
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 280
Default Copy VB code to other workbook?

Take a look he
http://www.cpearson.com/excel/vbe.htm

"john Dijkman" wrote in message
...
Dear all,

I build the new workbooks from scratch and would like to
copy some VB code to the new workbook(s).

I am trying to copy the following code to the new workbook
("thisworkbook" module) as discussed and posted in "How to
write code to module" (03/04/03).

Private Sub Workbook_Activate()
Application.Run "TPBQ11.xls!CrMn"
End Sub

This is the sad attempt I made which does not work:

Sub test()
Application.VBE.MainWindow.Visible = False
Set TempModule = ActiveWorkbook.VBProject.VBComponents
("Thisworkbook")
strCode = "Private Sub Workbook_Activate()" & vbCr & _
"On Error Resume Next" & vbCr
& "Application.Run " & Chr(34) & "TPBQ11.xls!CrMn" & Chr
(34) & vbCr & _
"End Sub"
TempModule.CodeModule.AddFromString strCode
End Sub

I cannot find anything that explains how to do this and
cannot make the sample to wrk.

Any help would be really appreciated.

Kind reagards.

John



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Copy VB code to other workbook?

Bob thanks for the email, very interesting.

I still get the following error messge:
Runtime error 1004
Programatic access to Visualbasic project is not trusted.

I have:
Security setting medium (excel 2002, OS:Win 2000) and a
personal dig. certificate.

Any idea why I still get this error message for the
following macro:

Sub test()
Dim StartLine As Long
With ActiveWorkbook.VBProject.VBComponents
("Thisworkbook").CodeModule
StartLine = .CreateEventProc
("Activate", "workbook") + 1
.InsertLines StartLine, "msgbox ""hellome"",
vbOKonly"
End With
End Sub

Thanks again for all your help, really appreciated.

Kind regards,

John





-----Original Message-----
Take a look he
http://www.cpearson.com/excel/vbe.htm

"john Dijkman" wrote in message
...
Dear all,

I build the new workbooks from scratch and would like to
copy some VB code to the new workbook(s).

I am trying to copy the following code to the new

workbook
("thisworkbook" module) as discussed and posted in "How

to
write code to module" (03/04/03).

Private Sub Workbook_Activate()
Application.Run "TPBQ11.xls!CrMn"
End Sub

This is the sad attempt I made which does not work:

Sub test()
Application.VBE.MainWindow.Visible = False
Set TempModule =

ActiveWorkbook.VBProject.VBComponents
("Thisworkbook")
strCode = "Private Sub Workbook_Activate()" & vbCr

& _
"On Error Resume Next" & vbCr
& "Application.Run " & Chr(34) & "TPBQ11.xls!CrMn" & Chr
(34) & vbCr & _
"End Sub"
TempModule.CodeModule.AddFromString strCode
End Sub

I cannot find anything that explains how to do this and
cannot make the sample to wrk.

Any help would be really appreciated.

Kind reagards.

John



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copy VB code to other workbook?

http://support.microsoft.com/default...b;EN-US;282830
PRB: Programmatic Access to Office XP VBA Project Is Denied

--
Regards,
Tom Ogilvy


John wrote in message
...
Bob thanks for the email, very interesting.

I still get the following error messge:
Runtime error 1004
Programatic access to Visualbasic project is not trusted.

I have:
Security setting medium (excel 2002, OS:Win 2000) and a
personal dig. certificate.

Any idea why I still get this error message for the
following macro:

Sub test()
Dim StartLine As Long
With ActiveWorkbook.VBProject.VBComponents
("Thisworkbook").CodeModule
StartLine = .CreateEventProc
("Activate", "workbook") + 1
.InsertLines StartLine, "msgbox ""hellome"",
vbOKonly"
End With
End Sub

Thanks again for all your help, really appreciated.

Kind regards,

John





-----Original Message-----
Take a look he
http://www.cpearson.com/excel/vbe.htm

"john Dijkman" wrote in message
...
Dear all,

I build the new workbooks from scratch and would like to
copy some VB code to the new workbook(s).

I am trying to copy the following code to the new

workbook
("thisworkbook" module) as discussed and posted in "How

to
write code to module" (03/04/03).

Private Sub Workbook_Activate()
Application.Run "TPBQ11.xls!CrMn"
End Sub

This is the sad attempt I made which does not work:

Sub test()
Application.VBE.MainWindow.Visible = False
Set TempModule =

ActiveWorkbook.VBProject.VBComponents
("Thisworkbook")
strCode = "Private Sub Workbook_Activate()" & vbCr

& _
"On Error Resume Next" & vbCr
& "Application.Run " & Chr(34) & "TPBQ11.xls!CrMn" & Chr
(34) & vbCr & _
"End Sub"
TempModule.CodeModule.AddFromString strCode
End Sub

I cannot find anything that explains how to do this and
cannot make the sample to wrk.

Any help would be really appreciated.

Kind reagards.

John



.



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
Macro to copy an image (or picture) from one workbook to a new sheetin another workbook Ruchir Excel Worksheet Functions 1 July 25th 08 07:29 AM
Excel-how to link source workbook to copy of destination workbook D Lynn Excel Worksheet Functions 1 May 29th 08 05:36 PM
Help...Code to copy sheet from closed workbook [email protected] Excel Discussion (Misc queries) 1 March 28th 07 08:52 PM
Copy empty cells from one workbook to another - Code Dave Peterson Excel Discussion (Misc queries) 1 September 23rd 05 02:10 PM
copy and paste using code from workbook to workbook bigdaddy3 Excel Discussion (Misc queries) 2 September 14th 05 11:06 AM


All times are GMT +1. The time now is 11:01 AM.

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

About Us

"It's about Microsoft Excel"