Re: True or False

Tech-Archive recommends: Speed Up your PC by fixing your registry



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 !!!


.



Relevant Pages

  • Re: Word 2003 embedded/linked objects
    ... This code is contained in a module in the template. ... I don't put it in a header or footer, ... Dim appWord As Word.Application ... Dim strTestFile As String ...
    (microsoft.public.word.docmanagement)
  • Re: Switch between drives
    ... you want to know whether a folder exists, you can use the Dirfunction ... no Dim statement for the variable strFile that was used. ... haven't checked that the template actually exists in the folder. ... Dim strNetworkPath As String ...
    (microsoft.public.word.vba.general)
  • Re: Switch between drives
    ... you want to know whether a folder exists, you can use the Dirfunction ... no Dim statement for the variable strFile that was used. ... haven't checked that the template actually exists in the folder. ... Dim strNetworkPath As String ...
    (microsoft.public.word.vba.general)
  • Re: Shipping Label Design
    ... BusinessAddressStreet ... After changing the name of the file in the program to .dotx, my template ... Interestingly, when I saved the "label" which I made with your program, it ... It highlighted "Dim oWord As Word.Application" ...
    (microsoft.public.word.docmanagement)
  • Re: saving a doc with a filename from a merged field
    ... template will prompt for the number of the record you want to merge. ... Dim oDoc As Document ... Dim rNum As Range ... How you bookmark that rather depends on your ...
    (microsoft.public.word.vba.general)