Re: True or False
- From: "Greg Maxey" <gmaxey@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 1 Nov 2008 22:23:12 -0400
Jonathan,
Yes of course. My question was poorly worded. The problem I have having is
accessing the actual code module when templates are loaded as Addins.
I can use code like this to get the names of all procedures in a module when
the template in question is attached to an open document:
Option Explicit
Dim oTemplate As Template
Dim arrProcedures() As String
Sub Testing()
Dim aTemplate As Template
Dim pArray() As String
For Each aTemplate In Templates
If aTemplate.Name = "Test Template.dotm" Then
Set oTemplate = aTemplate
Exit For
End If
Next
pArray = ListProceduresInModule
MsgBox pArray(1)
End Sub
Function ListProceduresInModule() As String()
Dim stdModule As VBComponent
Dim i As Long
Dim Count As Long
Dim NumLines As Long
Dim strThisProcedure As String
Count = 0
Set stdModule = oTemplate.VBProject.VBComponents("Main")
NumLines = stdModule.CodeModule.CountOfLines
For i = stdModule.CodeModule.CountOfDeclarationLines + 1 To NumLines
If strThisProcedure <> stdModule.CodeModule.ProcOfLine(i, vbext_pk_Proc)
Then
If strThisProcedure <> "StopListing" Then
ReDim Preserve arrProcedures(Count)
arrProcedures(Count) = stdModule.CodeModule.ProcOfLine(i,
vbext_pk_Proc)
Count = Count + 1
strThisProcedure = stdModule.CodeModule.ProcOfLine(i, vbext_pk_Proc)
End If
End If
Next i
ListProceduresInModule = arrProcedures()
End Function
However when that template is loaded as an AddIn the procedure fails on:
Set stdModule = oTemplate.VBProject.VBComponents("Main")
Can't perform operation since the project is protected.
So I guess the is can you access the VBA code module on projects that are
loaded as AddIns?
Jonathan West wrote:
"Greg Maxey" <gmaxey@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message news:Om64Q$GPJHA.2392@xxxxxxxxxxxxxxxxxxxxxxx
Is the following statement technically true and accurate?
Code in template/global template AddIns is inaccessible to the VB
object module when the AddIn is loaded.
As I understand it, that is untrue. External access to the code is
available through two means
1. Use of the Application.Run method (applies to any Public Sub or
Function in any regular module)
2. Setting a reference to the code container through the Tools
Reference menu. (Enables access to class modules, UserForms and
Public Subs and Functions in regular modules.)
--
Greg Maxey - Word MVP
My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org
McCain/Palin '08 !!!
.
- Follow-Ups:
- Re: True or False
- From: Jonathan West
- Re: True or False
- References:
- True or False
- From: Greg Maxey
- Re: True or False
- From: Jonathan West
- True or False
- Prev by Date: RE: Run-time error '-2147417848 (80010108)
- Next by Date: BatchFileRenameSeqNumber Macro - Word 2007
- Previous by thread: Re: True or False
- Next by thread: Re: True or False
- Index(es):
Relevant Pages
|