|
Compiling a CAPP software with VBA in Word environment, encountered some problems, ask you experts.
Question 2: Insert a doc file whose file name is Selection.Text plus a few characters, how to achieve
Sub Insertion Acceptance Form ()
wpsno = Selection.Text
If wpsno = "C001" Then
Documents.Add Template: = _
"C:\WINDOWS\Application Data\Microsoft\Templates\acceptance order.dot", NewTemplate _
: = False, DocumentType: = 0
'Create a new file, and specify the template used for the new file as the acceptance form.dot
For i = 1 To a1
ChangeFileOpenDirectory "E:\capp\"
Selection.InsertFile FileName: = "C001-A.doc", Range: = "", ConfirmConversions: = _
False, Link: = False, Attachment: = False
'Insert a type A weld acceptance order, the number of acceptance orders is controlled by a1 cycle
Next i
End Sub
The problem now is that the name of the inserted file is related to the content of Selection.Text (wpsno), which is added with "-A". In other words, the content of wpsno is C001, and the file I need to insert is C001-A.doc.
The content of wpsno is C002, and the file I need to insert is C002-A.doc. I don't know how to set the file name of the inserted file to wpsno + "-A.doc". I tried it and it always prompts errors. Otherwise from C001 to C999, I can only use many if then else if…. Statements to input one by one to achieve. Please masters |
|