Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Macro

Status
Not open for further replies.

Molenski

IS-IT--Management
Jan 24, 2002
288
DE
Hi there, friend of mine created a Word Macro (97) which was supposed to send the active document to a certain address (coding as below) -

Sub Send()
'------------------------------------------------------------------------
'DIM SOME VARIBLES TO HOLD
'
'-------------------------------------------------------------------------
Dim strDocName As String
Dim Message, Title, Default, MyValue
Dim strDefaultAddress As String

' Get the current documents name
strDocName = "ActiveDocument.Name"
' Set the default userid to send to
strDefaultAddress = "bfhsc7tsm"

' get a input box to display the default address, or the user can
' enter a different one.
Message = "Enter a users login name" ' Set prompt.
Title = "Defualt Address" ' Set title.
Default = strDefaultAddress
MyValue = InputBox(Message, Title, Default)

' Send the document
Document("" & strDocName & "").HasRoutingSlip = True
With Documents("" & strDocName & "").RoutingSlip
.Subject = "Status Doc "
.AddRecipient Recipient:="" & MyValue & ""
.Delivery = wdAllAtOnce
End With
Documents("" & strDocName & "").Route

End Sub

- and when I run it Word keeps crashing with a Dr Watson error.

When I choose Debug/Compile Project I get a 'Compile Error Message' which states 'Sub or Function not defined' where I have underlined. My mate reckons this runs OK his end so has anyone got any ideas please.

Thanks.

Molenski

p.s. Please keep answers easy as I am a complete newbie!!!!



 
Hi, I put the corrections in red ... with comments
It have to work like that

Hope that helps

Sub Send()
Dim strDocName As String
Dim Message, Title, Default, MyValue
Dim strDefaultAddress As String

' Get the current documents name
strDocName = ActiveDocument.Name 'I remove your double-quotes that significate 'ActiveDocument.Name' is the value of strDocName
' Set the default userid to send to
strDefaultAddress = "bfhsc7tsm"

' get a input box to display the default address, or the user can
' enter a different one.
Message = "Enter a users login name" ' Set prompt.
Title = "Defualt Address" ' Set title.
Default = strDefaultAddress
MyValue = InputBox(Message, Title, Default)

' Send the document
Documents(strDocName).HasRoutingSlip = True 'The 's' was missing and double-quotes are not necessary
With Documents(strDocName).RoutingSlip 'same thing for double-quotes
.Subject = "Status Doc "
.AddRecipient Recipient:="" & MyValue & ""
.Delivery = wdAllAtOnce
End With
Documents(strDocName).Route ' same thing for double-quotes

End Sub

 
Thanks for this, but am still getting the same problem. Although now, when I debug there doesn't seem to be any problem, Word is still crashing.

Thanks for you help.
 
Humm ... this code works correctly on my PC

Is there any message when Word is crashing ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top