A
Alex
Hi,
(sorry for my very bad English !)
I'm using Word 97 on NT4 (ok, our boss takes his time to
upgrade our softwares !).
I'm creating a macro "UpgradeSourceCode" (called by the
AutoOpen macro) to upgrade the VBA source code while
opening the document:
this macro reads all .bas files (the up-to-date modules)
in a specific folder and:
- replaces the content of the existing modules by the code
found in the corresponding file
- imports the new modules
The only module that is not upgraded is the module where
UpgradeSourceCode and AutoOpen are.
Everything is working fine when I call UpgradeSourceCode
only.
But if AutoOpen call a macro located in an upgraded module
after calling UpgradeSourceCode, I get a Dr Watson (access
violation) !
I think the problem is that the source code is not
refreshed after the upgrade. I don't find any way to
refresh or reload it.
Can anybody help me ??
Alex
Below my code:
-----------------------------------------------------------
Sub AutoOpen()
UpgradeSourceCode
'Dr Watson appears just here (while CALLING
DocOpening, *NOT* while RUNNING DocOpening)
DocOpening ' <-- A macro located in an upgraded module
End Sub
Sub UpgradeSourceCode()
'Upgrade the source modules
Const strPath As String = "\\rixsffs04
\RditProdProg\RditPrPrMpr\"
Dim bolError As Boolean
Dim bolFound As Boolean
Dim bolExists As Boolean
Dim strFileName As String
Dim strModuleName As String
Dim comp As VBComponent
Dim i As Integer
On Error GoTo ErrUpgradeSourceCode
Application.StatusBar = "Upgrading the source code..."
With Application.VBE.ActiveVBProject
strFileName = Dir(strPath & "*.bas")
If strFileName <> "" Then
Do
strModuleName = Left(strFileName, Len
(strFileName) - 4)
bolFound = False
For i = 1 To .VBComponents.Count
If .VBComponents(i).Name =
strModuleName Then
bolFound = True
Exit For
End If
Next i
If bolFound Then
'The module exists -> replace his code
.VBComponents
(strModuleName).CodeModule.DeleteLines _
StartLine:=1, Count:=.VBComponents
(strModuleName).CodeModule.CountOfLines
.VBComponents
(strModuleName).CodeModule.AddFromFile strPath &
strFileName
Else
'The module does not exist -> import
.VBComponents.Import strPath &
strFileName
End If
strFileName = Dir
Loop While strFileName <> ""
End If
End With
Exit Sub
ErrUpgradeSourceCode:
MsgBox "An error occured while upgrading the source
code (" & Err.Description & ")." & vbCrLf & _
"The report will not be opened",
vbCritical, "MPR Version " & strVersion
ActiveDocument.Close SaveChanges:=False
End Sub
(sorry for my very bad English !)
I'm using Word 97 on NT4 (ok, our boss takes his time to
upgrade our softwares !).
I'm creating a macro "UpgradeSourceCode" (called by the
AutoOpen macro) to upgrade the VBA source code while
opening the document:
this macro reads all .bas files (the up-to-date modules)
in a specific folder and:
- replaces the content of the existing modules by the code
found in the corresponding file
- imports the new modules
The only module that is not upgraded is the module where
UpgradeSourceCode and AutoOpen are.
Everything is working fine when I call UpgradeSourceCode
only.
But if AutoOpen call a macro located in an upgraded module
after calling UpgradeSourceCode, I get a Dr Watson (access
violation) !
I think the problem is that the source code is not
refreshed after the upgrade. I don't find any way to
refresh or reload it.
Can anybody help me ??
Alex
Below my code:
-----------------------------------------------------------
Sub AutoOpen()
UpgradeSourceCode
'Dr Watson appears just here (while CALLING
DocOpening, *NOT* while RUNNING DocOpening)
DocOpening ' <-- A macro located in an upgraded module
End Sub
Sub UpgradeSourceCode()
'Upgrade the source modules
Const strPath As String = "\\rixsffs04
\RditProdProg\RditPrPrMpr\"
Dim bolError As Boolean
Dim bolFound As Boolean
Dim bolExists As Boolean
Dim strFileName As String
Dim strModuleName As String
Dim comp As VBComponent
Dim i As Integer
On Error GoTo ErrUpgradeSourceCode
Application.StatusBar = "Upgrading the source code..."
With Application.VBE.ActiveVBProject
strFileName = Dir(strPath & "*.bas")
If strFileName <> "" Then
Do
strModuleName = Left(strFileName, Len
(strFileName) - 4)
bolFound = False
For i = 1 To .VBComponents.Count
If .VBComponents(i).Name =
strModuleName Then
bolFound = True
Exit For
End If
Next i
If bolFound Then
'The module exists -> replace his code
.VBComponents
(strModuleName).CodeModule.DeleteLines _
StartLine:=1, Count:=.VBComponents
(strModuleName).CodeModule.CountOfLines
.VBComponents
(strModuleName).CodeModule.AddFromFile strPath &
strFileName
Else
'The module does not exist -> import
.VBComponents.Import strPath &
strFileName
End If
strFileName = Dir
Loop While strFileName <> ""
End If
End With
Exit Sub
ErrUpgradeSourceCode:
MsgBox "An error occured while upgrading the source
code (" & Err.Description & ")." & vbCrLf & _
"The report will not be opened",
vbCritical, "MPR Version " & strVersion
ActiveDocument.Close SaveChanges:=False
End Sub