| |

VerySource

 Forgot password?
 Register
Search
View: 35|Reply: 1

Insert a doc file whose file name is Selection.Text plus a few characters, how to achieve

[Copy link]

1

Threads

1

Posts

2

Credits

Newbie

Rank: 1

Credits
2

 China

Post time: 2020-1-6 20:40:01
| Show all posts |Read mode
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
Reply

Use magic Report

0

Threads

1

Posts

2

Credits

Newbie

Rank: 1

Credits
2

 China

Post time: 2020-3-24 11:15:01
| Show all posts
Try changing it to wpsno&"-A.doc" and see, string concatenation should be like this
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2020|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list