Thanks for the reply.
I'm pretty sure its a template that i am working on as its a .dotm extension.
The reason for the two command codes is because i tried the one it worked great but doesnt when its opened of the website as READ ONLY so i cut that code and pasted it somewhere else and used a new code to try and figure out how to get the document out of the read only but havent had much luck with the smaller second code.
Quote:
Are you sure all your code and userform are all in the file you're using as the template, and not in, say, your 'Normal' template? Does the useform and command button appear?
|
The userform and button do show up and i don't have them
Quote:
Unless you're emailing the temp document, this shouldn't be necessary.
|
Once its filled in the finished document does get emailed and and i'm trying to save it aswell under the name. The first line is the customer name and number and thats what its being saved as and the heading of the email is.
Quote:
You say "it worked perfectly on my machine aslong as you didnt click No in any of the message boxes". Obviously, you'll need to fix that. I note, for example, that you have code that asks the user whether a certain folder exists. Even if the user answers no to that prompt, your code then tries to save the file there. It's bound to fall over in that case. You either need to create the folder without asking the user or, if they choose 'no', asking them where to save the filke to and not proceeding until they've nominated a valid destination, to which the file is then saved.
|
At this point the not exiting the code properly when clicking as of now might just be the way it is. They are going to have to copy to that location anyway and most of the code is copied and pasted from code i found online and then tweaked to work properly when clicked yes. I tried having the code just run anyway but was getting errors so as of now it is what it is and the users will have to click ok anyway. More of a workaround then a fix for now.
I know the basics of word but once i get further into detail with macro's and Visual Basic i'm basically teaching myself as i'm building this document.
Thanks,
Randy
Here is some code i got to come close to what i'm attempting. The formatting is still alittle messed up as in the margins and spacing but it shows the tables in there. I put a note in there which is just a place holder to when i figured out how to acheived what i'm looking for then i was going to add the first code (the longer one) and piece that into there and it should in theory work the way i'd like it to.
Code:
Private Sub CommandButton1_Click()
Dim oSection As Section
Dim r As Range
Dim TempDoc As Document
Dim FirstPara As String
For Each oSection In ActiveDocument.Sections
Set r = oSection.Range
r.End = r.End - 1
Set TempDoc = Documents.Add
With TempDoc
ActiveDocument.Paragraphs(1).Range.FormattedText = r
FirstPara = r.Paragraphs(1).Range.FormattedText
FirstPara = Left(FirstPara, Len(FirstPara) - 1)
ChangeFileOpenDirectory "E:\Documents and Settings\" & Environ("username") & "\Desktop\EMS\"
.SaveAs FileName:=FirstPara & ".docx"
'Dont have this close yet make it print then email and close
.Close
End With
Set r = Nothing
Set TempDoc = Nothing
Next
End Sub