ive got a document that creates a new word doc and saves it as a name given by the user from an input box.
the macro then checks some checkboxes and attempts to copy the contents of many different word templates if the checkbox is checked.
however i cant get the copy and paste to work. heres the code and any help is greatly apreciated :crap:
code/
Private Sub CommandButton1_Click()
'
'
Dim cusnom As String
Dim prname As String
Dim fname As String
Dim details(1)
Dim final As String
'
cusnom = InputBox("Please enter the customer's company name.")
'
TextBox1 = cusnom
'
If CheckBox1 = True Then
prname = InputBox("Please Confirm Project Name/Number, (this MUST match the name given on the project folder)")
'
fname = prname & "Erection File" & ".doc"
details(0) = fname
details(1) = prname
'
'in theory this should copy all the templates from their seperate folders to the one single folder named prname or fname
'
'selecting textbox and writing details
'
TextBox2.Select
TextBox2 = prname
'
ChangeFileOpenDirectory _
"C:Documents and SettingsmynameDesktopErectionfile"
Documents.Open FileName:="erectorsinstructions.dot", ConfirmConversions:= _
False, ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto
Selection.WholeStory
Selection.Copy
Selection.Paste
'pastes selection
ActiveDocument.SaveAs FileName:=fname
'saves document as fname
'
End If
'
End Sub
code
basically how do i make the file saved as "fname" the activedocument so i can reference it in many copy paste functions.
ok but i still have a similar problem: the second if function does not recognise the file or window "final"
code/
Private Sub CommandButton1_Click()
'
'
Dim cusnom As String
Dim prname As String
Dim fname As String
Dim details(1)
Dim final As String
'
cusnom = InputBox("Please enter the customer's company name.")
'
TextBox1 = cusnom
'
If CheckBox1 = True Then
prname = InputBox("Please Confirm Project Name/Number, (this MUST match the name given on the project folder)")
'
final = prname & "Erection File"
fname = prname & "Erection File" & ".doc"
TextBox2.Select
TextBox2 = prname
'
Documents.Add DocumentType:=wdNewBlankDocument
ChangeFileOpenDirectory _
"C:Documents and SettingsDavid.BuckokeDesktoperectionfile"
Selection.InsertFile FileName:="KeyContacts.dot", Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
'
ActiveDocument.SaveAs FileName:=fname
End If
If CheckBox2 = True Then
TextBox2.Select
TextBox2 = prname
'
final = prname & "Erection File"
Windows(final).Activate
ChangeFileOpenDirectory _
"C:Documents and SettingsDavid.BuckokeDesktoperectionfile"
Selection.InsertFile FileName:="KeyContacts.dot", Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
End If
End Sub
Don't use copy/paste. Use Insert-File. I think you'll be alot happy. Also, investigage IncludeText as an option. This way, you're not even touching those files from which you want to "copy".
Red Hat's Rough Recovery From CFO Exit
Windows Live Finds a New, Pre-installed Home
|