I am try to make my first mail merge macro but I donĀ“t know how.
Can somebody help me? I need to generate an individual document from excel to word document, save it with the name of value in cell "A2" and then close word. Is it possible?
The word template path is: C:\Users\admin\Desktop\New folder (2)\all1.docx
The excel file path is: C:\Users\admin\Desktop\New folder (2)\source.xlsm
Source to mail merge is sheet Mailmerge
if i understand it correctly, you would like to save the worksheet to a MS word file? If yes, you could just use the saveAs function in excel-vba. you could record a macro then save the worksheet and viola, you now have the code :) just edit it..
Related
I'm completely new at scripting.
Excel online - I have created a bunch of new excel files in Powerautomate, but I need the file specific filename inside each document. How do I do this?
I have found - console.log(workbook.getName()), this give me the correct "output", but I cant write it to a cell.
It is cell "B2", in spreadsheet "Data".
Hope you are able to help,
Thanks
Edit:
I have a pile of excel files that have been generated via MS Powerautomate.
Powerautomate is generating a specific name for each file. I need this file name inside each excel file, to do a specific filtering in a bunch of data.
The following picture are in Danish.
screenshot of execl file
The name of this document is "Skabelon" and I would like to have this name automatically filled in spreadsheet "Data" "B2".
Is this possible?
//Mads
If I want to open a .oft document from Excel with VBA, I normally indicate the folder path to the .oft document in VBA.
Is it possible to attach/emmbed this .oft in the Excel file and indicate VBA to open it from the Excel file instead of indicating a folder path??
Thanks!
Here's a code sample for VB.NET from Word to give you an idea of the code constructs you need to use. Note that the Excel VBA model and Word VBA model differ and sometimes use different function/method names (I don't know for sure but this sometimes happens). Just search the guides at Microsoft.
For Each shp As InlineShape In wordDoc.Content.InlineShapes
If shp.Type = WdInlineShapeType.wdInlineShapeEmbeddedOLEObject Then
If shp.OLEFormat.ProgID.Contains("Word") Then
shp.open() ' Open the embedded Word document
end if
end if
next
I've managed to copy the cell from the embedded excel sheet and use Home/Paste special/Paste link/Unformatted text in the word document body. If I change the cell value in the embedded sheet, the linked field in the document is updated accordingly.
The problem is that, once I close and reopen the word document, the link cannot be updated, it says "word is unable to create a link to the object you specified". If I open the 'edit links to files' pane, the excel worksheet object seems to receive a new name every time the word document is reopened excel object name
Do you see a workaround in this situation?
Thanks in advance for your help.
Problem solved! The document was originally created in a previous version of Word, with the excel object contained inside a table. Probably the table and excel objects were not properly migrated when saving the file to the 2013 .docx format. The solution was to simply delete the table row where the excel was contained, reinsert the row, embed the worksheet and recreate the link from the excel to the document body. It seems that the table and excel object were somehow reinitialized and the link is updating as it should.
I have a .csv file which I can export and from which I need to copy data into word.
I know how to get the relevant data from Excel and format my .csv file with VBA, however I don't know how to get my data from that Excel file to Word.
Basically this is how a line of my formatted .csv file looks (I Got rid of all the info I don't need).
For clarification: 1st long nr. is personnel 2nd one is token.
And I need to fill that info into the following table in word (Not everything gets filled in).
And one extra thing, depending on the extention of the email address #mc or #lmc, I need a different file opened (Different languages). How would I best do that?
Possible algorithm:
In your Excel document, develop a VBA macro that
Copy data/elements from Excel document
Open your word document
Paste excel data to word document (to the places you want)
Save word document
Close word document
Here is some code for inspiration of how to do that.
I have a VBScript and a method that inserts a picture from a .jpeg file into and excel sheet. I will like for the picture to save to the excel sheet so that when the excel file is sent to another person, they can view the picture.
I have noticed that picture links to the local folder on my computer from which i copied it.
Is there a way to save the inserted picture to be part of the Excel document?
This is my method
set attachment = .Pictures.Insert(path)
The Shapes.AddPicture Method has a parameter to specify whether
To save the picture with the document.
This solution to the same problem replaces .Insert with .AddPictured successfully (German, sorry).