Change destination storage location

Christoph99

New Member
Joined
Dec 21, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Generally, I would like to paste the data from an excel file into a word template (both in the same folder) and then save it under a variable name.
If I paste my code directly into the excel file, it works.
But now I want to save this macro in my personal folder, so that I can use the macro with different excel files.
Thereby 3 problems arise:
1. the data is no longer transferred to the template.
2. the final file is saved in my personal folder and not with the template and excel file in the folder
3. the file name is wrong. The variable data from the excel is missing

Here is my code:



VBA Code:
Sub ExportToWordCasualty()

'Activate library

Dim wordapp As New Word.Application
Dim doc As Word.Document
Dim Zeile As Long

Zeile = ActiveCell.Row


'Make Word visible
wordapp.Visible = True

   
'Open Word file
Set doc = wordapp.Documents.Open("J:\I\Kartoffel\Template_Casualty_Muster.docx")
   
'fill word file with Excel data
doc.Bookmarks("Bodily_Injury").Range.Text = Tabelle1.Cells(Zeile, 6).Value
doc.Bookmarks("Construction_Liability").Range.Text = Tabelle1.Cells(Zeile, 8).Value


'Save Word file
 doc.SaveAs2 ThisWorkbook.Path & "\Casualty_" & Tabelle1.Cells(Zeile, 2).Value & "_" & Tabelle1.Cells(Zeile, 1).Value & "_" & Tabelle1.Cells(Zeile, 17).Value & ".docx"
   
'Close Word file
doc.Close SaveChanges:=False



'Close Word file
wordapp.Quit

End Sub


Thx for help
 
Last edited by a moderator:

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Change destination storage location
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,214,895
Messages
6,122,128
Members
449,066
Latest member
Andyg666

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top