phred_the_cat
asked on
How do I clear variables from Word
Ok
Here is the code I'm using
Main Module (all the variable are here):
Sub Main()
Dim oform As frmEZDocs
Set oform = New frmEZDocs
oform.Show vbModal
Set oform = Nothing
End Sub
Form "EZDocs" (Main Form)
collects most of the variables, and launches the various subroutines...for example, a power of attorney routine below:
'This is the main subroutine for this form
Private Sub cmdGPOA_Click()
On Error Resume Next
Dim wrdGPOA As Word.Application
Dim strTemplate As String
strTemplate = "C:\EZDocs\templates\GPOA. dot"
Set wrdGPOA = GetObject(, "Word.Application")
If wrdGPOA Is Nothing Then
Set wrdGPOA = CreateObject("Word.Applica tion")
End If
With wrdGPOA
.Documents.Add (strTemplate)
wrdGPOA.Visible = True
GetDate
ExpireDate
SubExpireDate
SubFindReplaceName
SubFindReplaceSSN
SubFindReplaceState
SubFindReplaceGPOAAgent
SubFindReplaceDate
End With
'Close Word
wrdGPOA.Quit
'Release resources
Set wrdGPOA = Nothing
End Sub
I run this from one of my forms, and it takes information from forms to automate a power of attornet. It runs fine, but after I make the first document, when I attempt to launch a second document...it won't go...no error...and something is happening in background, but no product output. Is there some way to put a "reset" button on the form(s) so that all variables are reset, without haveing to exit and reload the program
thanks!
Here is the code I'm using
Main Module (all the variable are here):
Sub Main()
Dim oform As frmEZDocs
Set oform = New frmEZDocs
oform.Show vbModal
Set oform = Nothing
End Sub
Form "EZDocs" (Main Form)
collects most of the variables, and launches the various subroutines...for example, a power of attorney routine below:
'This is the main subroutine for this form
Private Sub cmdGPOA_Click()
On Error Resume Next
Dim wrdGPOA As Word.Application
Dim strTemplate As String
strTemplate = "C:\EZDocs\templates\GPOA.
Set wrdGPOA = GetObject(, "Word.Application")
If wrdGPOA Is Nothing Then
Set wrdGPOA = CreateObject("Word.Applica
End If
With wrdGPOA
.Documents.Add (strTemplate)
wrdGPOA.Visible = True
GetDate
ExpireDate
SubExpireDate
SubFindReplaceName
SubFindReplaceSSN
SubFindReplaceState
SubFindReplaceGPOAAgent
SubFindReplaceDate
End With
'Close Word
wrdGPOA.Quit
'Release resources
Set wrdGPOA = Nothing
End Sub
I run this from one of my forms, and it takes information from forms to automate a power of attornet. It runs fine, but after I make the first document, when I attempt to launch a second document...it won't go...no error...and something is happening in background, but no product output. Is there some way to put a "reset" button on the form(s) so that all variables are reset, without haveing to exit and reload the program
thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
PaulHews is absolutely right. I had same problem with
Excel, I fixed after seeing Paul's comments.
Chandu
Excel, I fixed after seeing Paul's comments.
Chandu
ASKER
Thanks man...now I just gotta figure out how to fix it
Well, if it is the problem I mentioned earlier, hunt through all the code looking for unqualified Word objects. eg.
Unqualified.
Selection.Paste
Qualified (corrected)
wrdGPOA.Selection.Paste
Any internal Word object (Range, Selection, ActiveDocument, etc.) must be prefaced in this way.
I am still not sure that this is the problem. If it isn't let me know and I'll get CS to delete the question and refund your points so that you can ask it again.
Unqualified.
Selection.Paste
Qualified (corrected)
wrdGPOA.Selection.Paste
Any internal Word object (Range, Selection, ActiveDocument, etc.) must be prefaced in this way.
I am still not sure that this is the problem. If it isn't let me know and I'll get CS to delete the question and refund your points so that you can ask it again.
Unqualified use of an internal Word object causes problems. Qualifying the object fixes it.
This link documents the problem
http://support.microsoft.com/support/kb/articles/Q189/6/18.ASP