Andreamary
asked on
Word macro that references an Excel file to update work order numbers
I would like a macro for Word 2016 that searches through the file for each work order number, then checks for the work order number in Column A of an Excel list, and if found, then replaces the work order number in the Word file based on the value listed in Column C of the Excel list. (Column C is a formula that concatenates Column A [the work order number] and Column B [initials]).
Additional notes:
The format of the work order number is:
####-####### (4 numbers, followed by a dash, then 7 numbers)
I have attached the following files:
1. Cycle_Changes_Depot.docx
2. WO_Initials_List.xlsm
3. Cycle_Changes_Depot_After_ Update.doc x (this is an example file of the results I am looking for after the macro is run)
I hope I've included all the relevant information/files. Please let me know if you have any questions or need anything further.
Thanks!
Andrea
Cycle_Changes_Depot.docx
Cycle_Changes_Depot_After_Update.docx
WO_Initials_List.xlsm
Additional notes:
- Excel spreadsheet is in a table format
- Column A and Column C are dynamic named ranges, as the number of work orders listed in the spreadsheet will change/fluctuate
- I would like the original formatting of the work order number in Word to be retained when the work order number is updated in the file.
- If the work order is not found in Column A of the Excel file, then no action is required in the Word file.
The format of the work order number is:
####-####### (4 numbers, followed by a dash, then 7 numbers)
I have attached the following files:
1. Cycle_Changes_Depot.docx
2. WO_Initials_List.xlsm
3. Cycle_Changes_Depot_After_
I hope I've included all the relevant information/files. Please let me know if you have any questions or need anything further.
Thanks!
Andrea
Cycle_Changes_Depot.docx
Cycle_Changes_Depot_After_Update.docx
WO_Initials_List.xlsm
ASKER
Hi Graham,
Thanks for your quick response. I've added this macro into my Excel file. When I try to run it, I get a compile error on the following line:
I have attached the screen capture of the error in hopes that it can be resolved...
Thanks,
Andrea
Compile_Error.PNG
Thanks for your quick response. I've added this macro into my Excel file. When I try to run it, I get a compile error on the following line:
Dim wdApp As Word.Application
I have attached the screen capture of the error in hopes that it can be resolved...
Thanks,
Andrea
Compile_Error.PNG
ASKER
Hi Graham,
Update: I figured out the issue above (Tools > References > checking MS Word) and then ran the macro, which worked perfectly, thanks! So please ignore my previous response.
One thing I realize now, and should have included in my question, is that we will be running it on the same Word files more than once as we add new work orders, so there will be a mix of work order numbers: some that have already been updated to match Column C of the Excel file, and some that are not updated.
Currently, when I rerun the macro, it adds additional instances of "(*)", as shown below:
2017-0004801 (TPG) (TPG)
Is it possible to have the macro revised so that:
If the work order number is found in Column A, and the work order number in the Word file already matches the value in Column C of the Excel file, then no action required.
Graham, given that this is an additional request, please don't hesitate to let me know if I should be posing this as a new question instead of adding it to this one.
Thanks again for your assistance,
Andrea
Update: I figured out the issue above (Tools > References > checking MS Word) and then ran the macro, which worked perfectly, thanks! So please ignore my previous response.
One thing I realize now, and should have included in my question, is that we will be running it on the same Word files more than once as we add new work orders, so there will be a mix of work order numbers: some that have already been updated to match Column C of the Excel file, and some that are not updated.
Currently, when I rerun the macro, it adds additional instances of "(*)", as shown below:
2017-0004801 (TPG) (TPG)
Is it possible to have the macro revised so that:
If the work order number is found in Column A, and the work order number in the Word file already matches the value in Column C of the Excel file, then no action required.
Graham, given that this is an additional request, please don't hesitate to let me know if I should be posing this as a new question instead of adding it to this one.
Thanks again for your assistance,
Andrea
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Graham,
I'm sorry for my tardiness in responding - I was assigned to a special project this week and so this has been my first chance to review the updated macro. It works perfectly - I'm very pleased. Thanks so much!
Cheers,
Andrea
I'm sorry for my tardiness in responding - I was assigned to a special project this week and so this has been my first chance to review the updated macro. It works perfectly - I'm very pleased. Thanks so much!
Cheers,
Andrea
Open in new window