Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Workbook Reference Problem

I have a macro that generates a sub() that I use as a "macro template".
I then try to go and change the newly created sub template's name using
this code (below) - I borrowed and adapted from somewhere in the
internet. The worksheet "FileTrackingSheet" is opened. I jump from the
macro that just renerated the template to this RenameSub code. The
macro would not compile by itselft, but if I run it, it removes the
name of from the template sub and leaves the new name as "sub ()" which
gives me another compiling error. I think I am not able to reference
the workbook FileTrackingSheet correctly. Can someone take a look at my
code. Thanks. ~Pablo

Sub RenameSub()
Dim OldMacroName As String
Dim findtext As Long
Dim NewMacroName As String
Dim wbXL As Excel.Workbook

Set wbXL = Workbooks(FileTrackingSheet.xls).Select
Sheets(MSBs_Tracking).Select
NewMacroName = Range("B6").Text
OldMacroName = "ChangeNameofThisMacro"

With
ActiveWorkbook.VBProject.VBComponents("FileTrackin gCompanyList").CodeModule
On Error GoTo notfound
findtext = .ProcBodyLine(OldMacroName, prockind:=vbext_pk_Proc)
.ReplaceLine Line:=findtext, String:="Sub " & NewMacroName & "()"
End With
Exit Sub
notfound:
MsgBox "not found"
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Workbook Reference Problem

I figure it out. Thanks you all.


Pablo wrote:
I have a macro that generates a sub() that I use as a "macro template".
I then try to go and change the newly created sub template's name using
this code (below) - I borrowed and adapted from somewhere in the
internet. The worksheet "FileTrackingSheet" is opened. I jump from the
macro that just renerated the template to this RenameSub code. The
macro would not compile by itselft, but if I run it, it removes the
name of from the template sub and leaves the new name as "sub ()" which
gives me another compiling error. I think I am not able to reference
the workbook FileTrackingSheet correctly. Can someone take a look at my
code. Thanks. ~Pablo

Sub RenameSub()
Dim OldMacroName As String
Dim findtext As Long
Dim NewMacroName As String
Dim wbXL As Excel.Workbook

Set wbXL = Workbooks(FileTrackingSheet.xls).Select
Sheets(MSBs_Tracking).Select
NewMacroName = Range("B6").Text
OldMacroName = "ChangeNameofThisMacro"

With
ActiveWorkbook.VBProject.VBComponents("FileTrackin gCompanyList").CodeModule
On Error GoTo notfound
findtext = .ProcBodyLine(OldMacroName, prockind:=vbext_pk_Proc)
.ReplaceLine Line:=findtext, String:="Sub " & NewMacroName & "()"
End With
Exit Sub
notfound:
MsgBox "not found"
End Sub


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
Setting Reference to another WorkBook-Problem davidm Excel Programming 2 March 13th 06 03:00 AM
problem sharing an excel workbook when my formulas reference user. Waiward Engineer Excel Programming 1 March 1st 05 05:41 PM
Reference code in another workbook from a calling workbook Datasort Excel Programming 1 January 4th 05 01:13 AM
Problem with =sum(offset(cell reference,w,x,y,z). I want cell reference to be variable [email protected] Excel Worksheet Functions 2 December 11th 04 12:00 AM
Reference to other workbook problem Terry Carpenter Excel Programming 0 April 3rd 04 01:45 AM


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

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"