Automate Mail Merge to Save Each Record Individually in MS Word | Step-By-Step Word VBA Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ต.ค. 2024

ความคิดเห็น • 262

  • @jiejenn
    @jiejenn  4 ปีที่แล้ว +4

    Want to add couple things here:
    1) When your table header name contains a space, for example Account Name, because a data source field cannot have a space, VBA will automatically replace space with an underscore. So when you type your DataFields' name, instead of DataFields("Account Name").value, you want to use DataFields("Account_Name").value.
    2) I will be working on a Mail Merge Utility with a UI with to eliminate the need to write VBA code. Also looking adding few useful features to enhance the functionality.
    3) and try not use special characters in your file name.
    And lastly, thank you for all of your support and views. I appreciate it.

    • @nageshnagasubramanian1185
      @nageshnagasubramanian1185 2 ปีที่แล้ว

      Jie Jenn, this was very useful. Can you tell how to few lines of code to combine 2 or more pdf files together in this script of yours?

  • @dariotedesco8652
    @dariotedesco8652 7 หลายเดือนก่อน +1

    thanks for your video. Unfortunately I have a problem when I run the code; a table will appear to confirm data source, I click on Show all and retreive my data source file choosing "Excel files ODBC (*xlsx), then I have the SelectTable window, I click on Options, Show, and I tick everything. I select the sheet where the specified column is, the window closes and then nothing happens. Do I maybe do something wrong?
    Thanks

  • @ra11han_
    @ra11han_ 3 ปีที่แล้ว +1

    For me it kept crashing on the lines below, but by declaring the parameters for Filename/FileFormat (save as in Word - I used the filename from concatenating 2 fields within the Excel data file) and outputFileName/exportformat (to export to pdf) meant that it worked:
    TargetDoc.SaveAs2 FileName:=FOLDER_SAVED & .DataSource.DataFields("filename").Value & ".docx", FileFormat:=wdFormatDocumentDefault
    TargetDoc.ExportAsFixedFormat outputfilename:=FOLDER_SAVED & .DataSource.DataFields("filename").Value & ".pdf", exportformat:=wdExportFormatPDF
    Anybody else gets stuck with that, you could also try that.
    Brilliant work Jie Jenn, saved me so much time - it's very much appreciated!

  • @stuartsharp8071
    @stuartsharp8071 4 ปีที่แล้ว +1

    Good tutorial, although not sure what I have done wrong. Managed to take a 49 page (49 individual letters) mail merged document and end up with 49 versions of the same each with the 49 pages each, instead of 49 documents with a letter each.

  • @imranism
    @imranism 5 ปีที่แล้ว +4

    This is amazing, It is a generic tool which can save each record from Excel in a customized pdf or word template.

  • @Ryangaming862
    @Ryangaming862 4 ปีที่แล้ว +2

    I cannot thank enough for this tutorial, very useful and extremely helpful for someone like me. hours of work in minutes. thanks once again for sharing your knowledge :)

  • @Master-dh3xl
    @Master-dh3xl 3 ปีที่แล้ว

    Well done!
    but I have question with the sql statement
    if want to retrieve data from row 2 to row 10
    how can I do with it?
    .OpenDataSource Name:=SOURCE_FILE_PATH, sqlstatement:="SELECT * FROM [databases$]"
    Thanks you.

  • @ngrant8822
    @ngrant8822 5 ปีที่แล้ว +1

    Great video Jie Jenn, I have been struggling with the SaveAs2 comment. My Datafield has a '" | " character in the value, I want to save the file name as the 10 characters before the " | " character, can you help me?

    • @jiejenn
      @jiejenn  5 ปีที่แล้ว

      | is one of the characters cannot be used to create a file or folder name. You will have to use other characters that is valid.

  • @kamiwasielewski1119
    @kamiwasielewski1119 2 ปีที่แล้ว

    Hi, I am able to produce word and PDF but both file are empty ) no words insite. Can someone help.

  • @YippeeKanYe
    @YippeeKanYe 4 ปีที่แล้ว +1

    Hi Jie, Thank you for this video, very helpful. I have a question about formatting. The data that appears in the newly created word document does not have the proper formatting, i.e. Currency/Accounting/Percentage formatting in the excel file shows up as a general number in word. 6% would show up as 6.0 etc. Any ideas on how to fix this?

  • @elumalaimanohar563
    @elumalaimanohar563 ปีที่แล้ว

    i have run this code , error has occurred, line .OpenDataSource Name:=SOURCE_FILE_PATH, SQLstatement:="select * from [database$]" pls help any one

  • @robepineda25
    @robepineda25 3 ปีที่แล้ว

    hello i cant seem to pass the open data source i continue getting an error
    .OpenDataSource Name:=SOURCE_FILE_PATH, SQLStatement:="SELECT*FROM[database$]"
    is there a way that i can fix this?

    • @jiejenn
      @jiejenn  3 ปีที่แล้ว

      By look at your syntax, I guess your query should be SELECT * FROM [database$]

  • @julianspb6329
    @julianspb6329 5 ปีที่แล้ว +1

    Hello, Thank you very much for the video. When i try to run the code, a tab saying "select table" show ups and when i click okay it say that "Run-time error '5922' unable to find data source". Do you know what i am doing wrong? Thanks

    • @jiejenn
      @jiejenn  5 ปีที่แล้ว

      Check your code to see if there are any typos.

    • @parniunplugged7023
      @parniunplugged7023 4 ปีที่แล้ว

      @@jiejenn I also got same error. Its something to do with SQL Statement.

  • @robertanderson9915
    @robertanderson9915 3 ปีที่แล้ว

    After the OpenDataSource instruction, I get a pop-up which allows me to select the whole worksheet, but then .DataSource.RecordCount = -1. Any ideas why it is not finding my records? Mail merge works normally so I'm sure the source data is ok.

  • @rajivraj6441
    @rajivraj6441 ปีที่แล้ว

    Thanks for the information, what if I want to save only 1 or 2 letters from the table and not the rest. How can this be done.

  • @LisaLevy-fk3cv
    @LisaLevy-fk3cv 5 หลายเดือนก่อน

    Thank you this is great, but I'm having a problem I hope you can help me with, when I try to run it it gives me a runtime error 4198 and points to the .opendatasource line. And suggestions?

    • @jiejenn
      @jiejenn  5 หลายเดือนก่อน

      The error is most likely due to invalid file path is provided.

  • @samanthawakefield8831
    @samanthawakefield8831 2 ปีที่แล้ว

    Hi. I’ve tried this and when I press F5 it runs like it’s working but it’s not opening a new document? Can you help? Thank you. The code I used is exactly the same as yours.

    • @jiejenn
      @jiejenn  2 ปีที่แล้ว

      Hi Samantha, I charge a fee of $10 to troubleshoot. If you are interested please let me know.

  • @satishhh01
    @satishhh01 3 ปีที่แล้ว

    Getting error as method or data member found for .active record
    Anyone please help

  • @tomdenapoli5313
    @tomdenapoli5313 3 ปีที่แล้ว

    Will this work on a Mac (Office 16). So far, no love.

  • @9716367288
    @9716367288 3 ปีที่แล้ว

    Omg..... Omg... Finaly i got vba code for mail merge for docx ans save file in docx... Thnk lost.... It very help full me.... 🙏🙏🙏

  • @andrewmarcou6164
    @andrewmarcou6164 2 ปีที่แล้ว

    Hi, Awesome. Quick question, if my word document has a table of contents and I wish to update it is there VBA code to do so for each file?

  • @catlovers776
    @catlovers776 3 ปีที่แล้ว

    Hello sir this is super amazing, when I run the macro I’m getting run time error 5922. The error is showing up in line 10 where we have the open data source. Would you mind helping me out

  • @undrawingend
    @undrawingend 2 ปีที่แล้ว

    Is it possible to have this make individual folders for each database reference and then have the files save in them locations ? Just out of interest as used this for batch documents in work and it’s been great however it requires moving said file into a folder for each individual letter any advice?

    • @jiejenn
      @jiejenn  2 ปีที่แล้ว

      Yeah, it is possible.

  • @simonsylow1365
    @simonsylow1365 2 ปีที่แล้ว

    Hello mate thank you so much for the toturtial! everything works however the documents crated seems to be all empty, can you help me with this problem?

    • @jiejenn
      @jiejenn  2 ปีที่แล้ว

      Replied your email.

  • @programming304
    @programming304 2 ปีที่แล้ว

    Hi. How do I get the client name to appear at the beginning of the Word document name once it is saved? The code right now always makes the client name appear at the end of the document name. Thanks.

    • @jiejenn
      @jiejenn  2 ปีที่แล้ว

      Once solution is to have a separate column containing the file name, and use that column as the file name instead.

  • @fongkaichian9073
    @fongkaichian9073 ปีที่แล้ว

    Facing a problem that once merge and the doc / PDF was empty but the PFD file name was correct, any idea?

    • @jiejenn
      @jiejenn  ปีที่แล้ว

      Makes sure your PDF content is extractable. If it is an image or encrypted, then it may not work.

  • @susannescherer7182
    @susannescherer7182 2 ปีที่แล้ว

    Hello. I have used this macro in the past with good success...a timesaver. Acrobat PDF Maker plug in with Mail merge now does create separate pdf files but still can't name them uniquely so this macro still remains very useful.
    I however now have an issue that the .pdf files being generated are all blank contents..the name of the file matches what I have in my excel mailmerge database so that source file appears to be set up correctly but the mail merge functionality itself doesn't seem to be running properly. any insight?
    I am using Office 365... is there perhaps a macro update to use on Office 365?

    • @jiejenn
      @jiejenn  2 ปีที่แล้ว

      Hard to tell without looking at your files. One common cause is due to margin is not set correctly.

    • @susannescherer7182
      @susannescherer7182 2 ปีที่แล้ว

      @@jiejenn thanks for the reply Jie. Can you clarity how to trouble shoot a margin issue? what should I be looking for?
      I am unable to send you the file as it contains confidential info. I did however need to really reduce both side, top and bottom margins to maximize the space for my document. thanks in advance

  • @viveksinghpratap
    @viveksinghpratap 2 ปีที่แล้ว

    Hi Jie. This really helped me a lot while I used for some letters last year and I’m really thankful for that. However, while I’m trying the same code on a new file:
    1. I’m getting separate files opened along with my letter format without any file name.
    2. Both word and pdf files saved in my folder read as “word found licked fields during update. Word can’t update locked fields “
    Kindly help. Thanks in advance

  • @PURVESHPRAJAPATI-tm7ds
    @PURVESHPRAJAPATI-tm7ds 3 ปีที่แล้ว

    Thanks. Jin. It is a very useful and timesaving clerical job which is widely used in corporates and other sectors.
    One my relative is in the HR department and he used to print and save the Increment / Bonus Letters individually by each employee and send by email to them. You can imagine how painful and time-consuming job for more than 500 employees.
    I shared this example and he is very happy to save his time by such Automation.
    Thanks Jin Again for your efforts.

  • @RESULTCELLSR
    @RESULTCELLSR ปีที่แล้ว

    Thank You for a clean crisp code! It has provided me the solution in the first go!!!

  • @eduardostewart412
    @eduardostewart412 4 ปีที่แล้ว +1

    Thank you so much. Initially had blank pages, had to import and run the module from within the project/document section, not the normal section in the VBA editor tree window on the left screen (don't know proper name right now).

    • @johnvanco2959
      @johnvanco2959 3 ปีที่แล้ว +1

      I have the same issue, what do you mean by running the module from within the project/document section ?
      Thanks for your help !

    • @eduardostewart412
      @eduardostewart412 3 ปีที่แล้ว +1

      @@johnvanco2959 in the vba window tree on the left. It will list a generic version and a line for the document you have open that you want to run it in. Click on the actual doc and then run/press play

    • @csm191
      @csm191 3 ปีที่แล้ว

      Thanks for posting your solution!

  • @valentinabs
    @valentinabs ปีที่แล้ว

    Hi Jie, how do I send the individual file to fax numbers? I need to create letters that will go to a list of about 1,000 providers, to let them know their new id number. But it has to go to their individual fax number which is in a column in the excel sheet. I saw there is an option: .Destination = wdSendToFax
    how do I use that?
    Thank you for your video. It is so illustrative.

    • @jiejenn
      @jiejenn  ปีที่แล้ว

      Do you mind send to a fax machine?

    • @valentinabs
      @valentinabs ปีที่แล้ว

      @@jiejenn i have the spread sheet with providers, provider id and their fax number. So each letter has to go to the provider fax machine. Is that possible?

    • @jiejenn
      @jiejenn  ปีที่แล้ว

      To be honest, I am not sure. I haven't fax anything since 2010, so don't know what to tell you.

  • @emiliazuloaga3602
    @emiliazuloaga3602 4 ปีที่แล้ว

    Hello,
    When I run the VBA and it gets to the .OpenDataSource line of code, another window opens up, the says “select table”, I then click my workbook, click options, then click “system tables” so that the table I am referencing shows up in the window. I then click that table, click ok then nothing happens. No error messages, nothing. Can you help? Thanks

    • @jiejenn
      @jiejenn  4 ปีที่แล้ว

      Not sure if I can help you given such little information you provided. If you want, you can send me your data file + Word document (must contain the VBA code) to TH-cam@LearnDataAnalysis.org and I can take a look when I have time.

  • @zarinamustapha8604
    @zarinamustapha8604 4 ปีที่แล้ว +1

    Hi, Thanks for the tutorial. It doesn't work when I followed it on a Mac, quite possibly something is different between the two platforms. The macro ran, no error, but no files have been created. I'm not an expert in VB, though

    • @jiejenn
      @jiejenn  4 ปีที่แล้ว

      Hi Zarina, I think the object references are a little bit different on Mac. Unfortunately I am not a Mac user nor do I own a Mac PC. Your best bet is look for someone who has a Windows PC and try the mail merge and see if it works.

    • @romellamarie5608
      @romellamarie5608 4 ปีที่แล้ว

      @@jiejenn i have the same problem with Zarina, and I'm running Windows. help?

    • @romellamarie5608
      @romellamarie5608 4 ปีที่แล้ว

      i.m using word 2013 .. is there a different?

    • @danwilson4860
      @danwilson4860 3 ปีที่แล้ว

      I have had the same difficulties. I was able to get the script to MOSTLY work though.
      Line 19: The 1 to TotalRecord doesn't seem to work, but if you replace TotalRecord with the actual total number of records then it works.
      Line 33: I cannot get it to save PDFs. If I comment out this line, the script will create unique word files for every merge record, but my Mac chokes on wdExportFormatPDF

  • @R0b3
    @R0b3 3 ปีที่แล้ว

    Works great form me!!! Thanks a lot for your script. ;-)

  • @feddyblade9908
    @feddyblade9908 5 ปีที่แล้ว

    Is it possible to make pdf file output encrypted. Usually i do manual save as page 1, input password xxx, next save as page 2 input password yyy, and so on....

  • @missyg3183
    @missyg3183 5 ปีที่แล้ว +1

    hi, thank you for this, i have a question - i keep getting a debugger error on the open source data line. i see your folder is in C drive, i have to use a W drive - is that the issue? also i get a pop up asking me to select a workbook. any suggestions would be really helpful. thank you!

    • @jiejenn
      @jiejenn  5 ปีที่แล้ว +1

      I don't think drive location should matter, but your error to me seems like Word cannot find the file. The pop up is caused by Word doesn't have the source file linked.
      If you want, you can send me your VBA code to youtube@learndataanalysis.org and I can take a look at it.

    • @StuartHough
      @StuartHough 5 ปีที่แล้ว

      same issue here

    • @StuartHough
      @StuartHough 5 ปีที่แล้ว

      I fixed this by unselecting the 'preview results' option in word. It then worked fine!

  • @ashleybradley3895
    @ashleybradley3895 3 ปีที่แล้ว

    Hello, I just used this and it was very helpful and it did work, but when I open the certificates in my PDF or Word file, the document comes blank. How do I fix this?

    • @jiejenn
      @jiejenn  3 ปีที่แล้ว

      There's probably a typo somewhere in your code. This happened to a viewer recently, and he spotted a typo that was causing the issue.

  • @SonnyBamra_0
    @SonnyBamra_0 4 ปีที่แล้ว

    What if you have multiple letters for the same person? Could a file contain multiple letters for the same person?

  • @blogieblogger
    @blogieblogger 5 ปีที่แล้ว

    Hi JJ, I getting a 'Microsoft Data Link Error' which reads as 'Test connection failed because of an error in initializing provider. Cannot start your application. The workgroup information file is missing or opened exclusively by another user'.
    while I have not opened the excel file nor it is being used/accessed by anyother program. Please help.

  • @林春梅-e9c
    @林春梅-e9c 4 ปีที่แล้ว

    I have a question,
    If I just need the pdf File, Can I write a code to delete the files?
    or can I make a pdf file without creating a word document?
    Thank you.

    • @jiejenn
      @jiejenn  4 ปีที่แล้ว

      You can directly create the PDF without creating the word doc.

  • @joanaamorfajardo3056
    @joanaamorfajardo3056 2 ปีที่แล้ว

    This is very helpful. It helped me accomplish my task! Thank you so much!

  • @nstarz
    @nstarz 4 ปีที่แล้ว

    I get a "Run-time error '5491': The requested member of the collection does not exist.
    It creates one copy and crashes there. Any thing I can do?

    • @jiejenn
      @jiejenn  4 ปีที่แล้ว

      You have a typo somewhere.

  • @smithlithium06
    @smithlithium06 4 ปีที่แล้ว +1

    You have saved me a lot of time! Thank you!

  • @ghsskomal2458
    @ghsskomal2458 ปีที่แล้ว

    dear sir thank you for your tutorial

  • @thomaskenny6393
    @thomaskenny6393 4 ปีที่แล้ว

    The code gets to the "TargetDoc.Close False" line and then stops to ask me if I would like to save the document. I have to press yes, otherwise it does not continue. Do you know how to automate the "yes" clicking? Thank you in advance.

    • @thomaskenny6393
      @thomaskenny6393 4 ปีที่แล้ว

      I solved this problem by adding "If ActiveDocument.Saved = False Then ActiveDocument.Save" directly above "TargetDoc.Close False"

  • @Xaphoeous
    @Xaphoeous 4 ปีที่แล้ว

    THANK YOU! This video, and especially the link to the VBA code, saved me hours and hours of work!

  • @kitwong3913
    @kitwong3913 5 ปีที่แล้ว

    I tried this VBA. It works, but not same as what he says " Automate Mail Merge to Save Each Record Individually in MS Word". The VBA Mail Merge produces many records and saved in one file. I expected to have one record saved in one file.

    • @jiejenn
      @jiejenn  5 ปีที่แล้ว

      Most of the people seemed to have success with the script. I suspect there may be a typo or two somewhere. Have you try to step through each line and to see what does each line does? It is easier to figure out where the issue is that way.

  • @mauriciocovarrubias8255
    @mauriciocovarrubias8255 4 ปีที่แล้ว

    Thanks a lot for sharing this wonderful tool. As a public server I need to send legal sheets with same info to different people and it works great! I dont have great knowledge of VBA but you made it so easy. At first I had troubles but with patiente I made it work. Greetings fro México.

  • @m.khoerudin3816
    @m.khoerudin3816 4 ปีที่แล้ว

    thanks, very usefull, but how if want to save with two DataFields, example, name and date

  • @annaw7608
    @annaw7608 3 ปีที่แล้ว

    My documents are all being created, but they are all coming back blank. Anyone have any idea why that my be happening?

    • @maxtuck6820
      @maxtuck6820 3 ปีที่แล้ว

      Change MainDoc=ActiveDocument.

  • @japurba
    @japurba 4 ปีที่แล้ว +2

    This is great!! Thank you brother!

  • @suescherer5491
    @suescherer5491 4 ปีที่แล้ว

    Thanks so much for the tutorial. Very clear. Can you provide the macro text pls.?

  • @ndchannel_
    @ndchannel_ 3 ปีที่แล้ว

    Thank you for the tutorial. Anw, I wanna ask you one thing if you don't mind. How to save each record as PDF if my data source is .CSV not .XLSX? (background: I have some field that exceed 255 limit in mail merge, so I have to save it in CSV in order to make it work). Thank you.

    • @jiejenn
      @jiejenn  3 ปีที่แล้ว +1

      You should be able to change your data source from Excel to CSV.

    • @ndchannel_
      @ndchannel_ 3 ปีที่แล้ว

      ​@@jiejenn Thank you for your response. When I change my data source to csv, the formula can't work. Let say, if I type:
      Const SOURCE_FILE_PATH As String = "D/MyName/MyFile.csv",
      nothing will happen after this. It only could run if I use xlsx format (ex: MyFile.xlsx).
      How to make the formula work? (I use windows 10 and office 365)

  • @breodjebi
    @breodjebi 3 ปีที่แล้ว

    This is awesome. Thank you very much. Working perfectly fine

  • @viveknakarmi3411
    @viveknakarmi3411 3 ปีที่แล้ว

    You are a legend!!!Thanks for this.

  • @yogeshdesai3049
    @yogeshdesai3049 4 ปีที่แล้ว

    Thanks its very helpful kindly share the another vdo for all records save in one pdf format

  • @mcclusky21
    @mcclusky21 5 ปีที่แล้ว +1

    This was a lifesaver thank you so much for this workaround!!! I had to watch a few times, but very easy to follow. Had to remove the SQLStatement though.

    • @YippeeKanYe
      @YippeeKanYe 4 ปีที่แล้ว

      Same here, thank you Sharrod

    • @f.p.186
      @f.p.186 4 ปีที่แล้ว

      @@YippeeKanYe i have a problem with that line as well, did you delete the sql statement after the comma or the whole line? (. Opendatasource name=....)

    • @YippeeKanYe
      @YippeeKanYe 4 ปีที่แล้ว

      @@f.p.186 I deleted the whole line i.e. .Opendata...

  • @ramanandkashyap5167
    @ramanandkashyap5167 4 ปีที่แล้ว

    Woah!! This is awesome Jie. Thank you very much. Working perfectly fine.

  • @abdulbaig2099
    @abdulbaig2099 4 ปีที่แล้ว

    It was great help... i have one more ask i have in the corresponding column password to be input for that file. Note password is different for each file. May be you can think like a SSN Number or Driving licence number for each person as password for them. CAn you help please.

    • @jiejenn
      @jiejenn  4 ปีที่แล้ว

      If you want to include password to Word Document, the SaveAs2 method has a parameter called password, and you can supply your password to that parameter.
      TargetDoc.SaveAs2 FOLDER_SAVED & .DataSource.DataFields("Client_Name").Value & ".docx", FileFormat:= wdFormatDocumentDefault, Password:=""

    • @abdulbaig2099
      @abdulbaig2099 4 ปีที่แล้ว

      Thank you Sir! Appreciate your quick reply. however its like this for File 1 the password is 1234
      File 2 password is 4567 and so on and its different for each file like mail merge we have different name and id etc..so can we something to input password while saving only with the mail merge from the Excel sheet it can pickup the password

  • @ceciliaknights8306
    @ceciliaknights8306 3 ปีที่แล้ว

    Dude!!! This worked so well!! You saved me hours of work, thank you so so much!

  • @santrisholawat5526
    @santrisholawat5526 5 ปีที่แล้ว

    how to create with button of source_file & file save_as (dinamic path)?
    folder & filename picker

  • @mistysword
    @mistysword 5 ปีที่แล้ว +1

    Thanks so much for all the effort! This saved my day

  • @ashishyadavhr
    @ashishyadavhr 4 ปีที่แล้ว

    Thanks a lot for sharing this knowledge with us it was very useful. Please advise if we can separate individual documents from a mail merged consolidated file as well? can we use with the same method by making the source as that word file?

    • @jiejenn
      @jiejenn  4 ปีที่แล้ว

      Well you can, but depends on the document content organization. Are the pages number consistent for each file? or the page number varies.

  • @91alezander
    @91alezander 4 ปีที่แล้ว

    It is possible to generate a word template from every excel row individually. In excel I need a button to appear on every new row I populate with data and the button must open the word template that was fill with the data that I populate the row. And also i need the autofill word template to be save in a specified location. Thank you!

    • @jiejenn
      @jiejenn  4 ปีที่แล้ว

      Yeah it is doable, but because you want to tie each row per button, you will have to manually re-link the button to each row. It is a pretty time consuming process if you have many records though.

    • @91alezander
      @91alezander 4 ปีที่แล้ว

      @@jiejenn Thank you!

  • @capt336
    @capt336 5 ปีที่แล้ว

    Thank you for posting this video. The .Destination = WdSendtoNewDocument seems to make a long word file with every generated document from the Mail Merge put together. Any way how to change it so it just makes the one custom document for each line of source data?

    • @jiejenn
      @jiejenn  5 ปีที่แล้ว

      Not sure if it follow. Can you be more specific.

  • @JOSHI-l1m
    @JOSHI-l1m 4 ปีที่แล้ว

    mind blowing, superb knowledge you holding and speed of writing macros

  • @JTPedersen
    @JTPedersen 4 ปีที่แล้ว

    Greatly appreciate your sharing this. Struggled to find an effective solution elsewhere. Been awhile since I coded last. Your delivery was excellent and easy to replicate. Only real hiccup I had was the SQL code. SOURCE_FILE_PATH was correct (I set a Watch) yet stepping through the line, I'd consistently get the full filename path truncated (e.g. c:\1\2\3\file.xlsx, came back as c:\1\2\file.xlsx). Solution: Replace database$ with the name of the table containing the data in the xlsx. Worked beautifully.
    Thanks!

    • @jiejenn
      @jiejenn  4 ปีที่แล้ว

      Glad my video helped.

  • @undrawingend
    @undrawingend 3 ปีที่แล้ว

    I have used this to help me with my work and have colleagues asking to use it - when I have shared it to them they can’t get it to work is their a way in which this can be used by multiple users ?

    • @jiejenn
      @jiejenn  3 ปีที่แล้ว +1

      There should be an error message inducting the issue.

    • @undrawingend
      @undrawingend 2 ปีที่แล้ว

      Managed to resolve thanks

  • @ihzaraki
    @ihzaraki 3 ปีที่แล้ว

    Thank you so much, it's so easy to follow your step

  • @reallyefficient
    @reallyefficient 4 ปีที่แล้ว

    Did anyone solve for Word for Mac!?!?! This has been something I have been working on for FAR too long!

    • @jiejenn
      @jiejenn  4 ปีที่แล้ว

      Unfortunately, VBA support on IOS is very limited, and some of the Word objects are missing comparing to Windows. If you are on a Mac, my recommendation is to either borrow a Window's PC or look for an alternate.

  • @lrgamage88
    @lrgamage88 3 ปีที่แล้ว

    how to custom add starting and ending record?

  • @claudiaolaru990
    @claudiaolaru990 5 ปีที่แล้ว

    Hello. Great work. I tried the macro but I get the following error 5941, element not found for the line TargetDoc.SaveAs2 FOLDER_SAVED & .DataSource.DataFields("Client_Name").Value & ".docx", wdFormatDocumentDefault Do you have any idea why? Thank you very much

    • @giorgiolupato6553
      @giorgiolupato6553 5 ปีที่แล้ว

      you have to replace "Client_Name" with the header (field) of your input table

    • @santrisholawat5526
      @santrisholawat5526 5 ปีที่แล้ว

      @@giorgiolupato6553 how to create with button of source_file & file save_as (dinamic path)?

  • @tameraziz2104
    @tameraziz2104 3 ปีที่แล้ว

    Perfect, thank you so much..

  • @michaelfaw
    @michaelfaw 5 ปีที่แล้ว

    I do follow the step that you give. But why the result is blank document and pdf? any idea about this issue?

    • @jiejenn
      @jiejenn  5 ปีที่แล้ว +1

      Without looking at your code, your file, and the error you get, it is nearly impossible to help.
      I would suggest you post your question on Microsoft Word Forum.

  • @soaresian
    @soaresian 4 ปีที่แล้ว

    Thanks this is very helpful and simplified compared to all the complex threads out there.

  • @Stonium
    @Stonium 3 ปีที่แล้ว

    I love you.

  • @nelsoncardona4910
    @nelsoncardona4910 3 ปีที่แล้ว

    Thanks man!

  • @tsang9413
    @tsang9413 4 ปีที่แล้ว

    Thanks. This is very useful & I can successfully try even I don't have any IT knowledge. Thanks so much!! And would like to ask if it is possible to set a password in the PDF??

    • @jiejenn
      @jiejenn  4 ปีที่แล้ว +1

      VBA Save function doesn't have set password option. You might have to use 3rd party software to automatically set PDF files' password.

    • @tsang9413
      @tsang9413 4 ปีที่แล้ว

      @@jiejenn Thanks a lot^^

  • @abdulwahedcatran8349
    @abdulwahedcatran8349 5 ปีที่แล้ว +1

    Thank you so much please how to add a picture to the file

    • @jiejenn
      @jiejenn  5 ปีที่แล้ว +1

      I'm not following your question.

    • @abdulwahedcatran8349
      @abdulwahedcatran8349 5 ปีที่แล้ว +2

      @@jiejenn Let's say we have a logo folder for each client and we want to put this image on the customer's message

  • @devenderrohilla
    @devenderrohilla 4 ปีที่แล้ว

    Very nice...great way to explain and fully functional...thank you

  • @lashadolenjashvili9775
    @lashadolenjashvili9775 4 ปีที่แล้ว

    Hey Jie Jenn, thanks for this tutorial. I am trying to do the same with Publisher, but I can't figure out what to do. Could you please somehow look at my code and give me an advice?

    • @jiejenn
      @jiejenn  4 ปีที่แล้ว

      Do you mean Windows publisher?

    • @lashadolenjashvili9775
      @lashadolenjashvili9775 4 ปีที่แล้ว

      @@jiejenn I am very glad you answered. Yes, Microsoft Publisher. I have Mail Merge, it is connected to excel sheet. And I want to convert each record to separate PDF. I wrote a simple script, it generates PDFs with correct names, but for some reason each PDF contains only the second record from excel.

  • @kethanchordia
    @kethanchordia 4 ปีที่แล้ว

    Amazing will save me a lot of time. Thank you. Subscribed for life :-)

  • @jynxie88
    @jynxie88 2 ปีที่แล้ว

    You are a lifesaver! There were some moments where I hit a roadblock, but meddled here and there and it saved my team's time, a LOT of it! Thank you so much sir.

    • @jiejenn
      @jiejenn  2 ปีที่แล้ว +1

      Glad my video helped. Cheers.

  • @kazisazzad9257
    @kazisazzad9257 4 ปีที่แล้ว

    Hi, Many thanks for sharing this tutorial. It's amazing and so helpful. It's saving both in word and pdf format; is there any way to avoid saving in word format- please advise.

    • @jiejenn
      @jiejenn  4 ปีที่แล้ว +1

      To avoid saving the word file, I think you can just comment out the line that saves the word file.

  • @ogechinnadozie7284
    @ogechinnadozie7284 4 ปีที่แล้ว

    Thank you Jie Genn, the video explains all I'm looking for.
    I'm practically new with VBA Codes and I'm having a hard time understanding how you went about the "destination" which bears the mail merge automation. Could you do a little explanation on that?
    Thanks.

    • @jiejenn
      @jiejenn  4 ปีที่แล้ว

      Not following your question. What do you mean by "destination"? Do you mean save your files in a different folder?

    • @ogechinnadozie7284
      @ogechinnadozie7284 4 ปีที่แล้ว

      I meant the first line " folder_saved as string" the folder named "destination" I would like to know it's content and how to go about it?
      I know the second file is the Excel sheet containing the data. Can I work with an "xslm" file in this case

  • @Kamal-sh1km
    @Kamal-sh1km 4 ปีที่แล้ว

    Hi, i want to get output file as .jpg format tried changing extension, but it doesnt work.

    • @jiejenn
      @jiejenn  4 ปีที่แล้ว

      I don't think it is possible to save as a jpg file.

    • @Kamal-sh1km
      @Kamal-sh1km 4 ปีที่แล้ว

      @@jiejenn hey jie thanks for reply.. or may be .png ( it is actually a certificate)

  • @rachitnirmal
    @rachitnirmal 4 ปีที่แล้ว

    You are savior! Thank you so much! This was smooth like anything!

  • @curlcurllocal
    @curlcurllocal 3 ปีที่แล้ว

    This is fantastic thanks for sharing

  • @helifox
    @helifox 2 ปีที่แล้ว

    Thank you very much, you save a lot of my time !!!

    • @jiejenn
      @jiejenn  2 ปีที่แล้ว

      Glad my video helped.

  • @npaverico
    @npaverico 4 ปีที่แล้ว

    What a great tutorial!! I have one question. I need to put a repeated name in the file name. For example "Approval - Project" . The word Approval has to be in all my file names. How do I include the in the macros?

    • @jiejenn
      @jiejenn  4 ปีที่แล้ว

      Within the TargetDoc.SaveAs2 you can concat any addition text you want to include. For example: TargetDoc.SaveAs2 FOLDER_SAVED & .DataSource.DataFields("Client_Name").value & " Approval - Project" & ".docx"

    • @hestertencate2980
      @hestertencate2980 2 ปีที่แล้ว

      @@jiejenn can you also do any additional text infront of the name? what would be the code? I've been trying but no idea...

  • @nullhas
    @nullhas 5 ปีที่แล้ว

    Hi Jenn,
    Pls advise, how to select rows to merge. I do not want to delete previous data.

    • @Permik123
      @Permik123 5 ปีที่แล้ว

      After you have connected to your database file on the Word Ribon choose edit recipient list. This is the Microsoft article on the subject.
      support.office.com/en-us/article/mail-merge-using-an-excel-spreadsheet-858c7d7f-5cc0-4ba1-9a7b-0a948fa3d7d3

  • @niloofarmaleki3573
    @niloofarmaleki3573 4 ปีที่แล้ว

    Hello, Many thanks for the video. This was great!
    My question is In case I want this to be done only for a group of the rows, for example lets say on a column I have category 1,2 and 3, and I want to do this for category 3 only, how should I modify the VBA to apply the filter?

    • @jiejenn
      @jiejenn  4 ปีที่แล้ว

      You can actually do that directly in a SQL statement. From the OpenDataSource statement, you can include what we called WHERE clause to include criteria.
      For example, assuming your column name is "Product Category" and you want to filter the dataset by label "category 1", you would write (noticing the extract double quotation):
      .OpenDataSource Name:=SOURCE_FILE_PATH, sqlstatement:="SELECT * FROM [$] WHERE [Product Category] IN (""Category 1"")"

    • @niloofarmaleki3573
      @niloofarmaleki3573 4 ปีที่แล้ว

      @@jiejenn
      Many Thanks
      But actually when I add this where clause, nothing happens... I sent you a video on your email, would you please kindly check?

  • @MrMarho
    @MrMarho 4 ปีที่แล้ว

    Nice tutorial! I have some questions though. What if you already have a conditional statement (like skip record if mergefield Field_name is ""). This means the loop will still try to run the total number of records. What is the workaround? Can be filename also be dynamic? i.e. a function of text Manipulation?

    • @jiejenn
      @jiejenn  4 ปีที่แล้ว

      Give me an example.

    • @MrMarho
      @MrMarho 4 ปีที่แล้ว

      @@jiejenn Let's say from Excel you have 2 fields; Name and DOB. Now when doing mailmerge in Word, you put a conditional saying skip record if DOB = "". Also In Excel, the Name field is a combination of Title, Fname, Mname, and Lname from an original database. So your name field in excel will come as "Miss Jane A. Doe" or "Mr. John Doe" if there's no Mname.
      This means when you do mailmerge you have just two fields name and DOB in word. From your tutorial, the code will go through the total number of records and save as .docx or export to .pdf regardless of what is in the field. This means it will even do a merge for empty fields as far as you have set up your mergefields in word as you would like them to be outputted.
      So this is what I would like to do, use pagecount to know the number of pages it needs to loop through OR use and IF statement in the VBA code to know what records to actually save indiviudual documents for. It will also extract just the first and last name from each record.

  • @beatricezhang7630
    @beatricezhang7630 5 ปีที่แล้ว +2

    Hi Jie, thank you so much for posting the tutorial. It is definitely what I need recently. I am new to VBA, and I tried to follow your video to make my mail merge works. There is an error "438" in the line of ".OpenDataSource Name:=source_file_path, SQLStatement:="SELECT * FROM [XXX$]", as i only change the sheet name you created to mine. Can you help me on this? Thanks!

    • @demodrift1
      @demodrift1 5 ปีที่แล้ว

      I have the same issue. Please help us!

    • @mcclusky21
      @mcclusky21 5 ปีที่แล้ว

      I had the same issue. Remove SQLStatement:="Select * From [Database$] and it should work

    • @dharmeshy3622
      @dharmeshy3622 4 ปีที่แล้ว

      instead of -database- statement use the sheet name of your data

  • @ScottAlexander68
    @ScottAlexander68 4 ปีที่แล้ว

    This is great and it works perfectly. I am wanting to expand on it a bit by selecting the records from the Excel file that have not been "processed" yet. I have that figured out, but I am trying to figure out how to update the excel field to show it as processed so the next time I run the macro, it doesn't pick that record. For example, I want to change the Processed field from No to Yes. Hopefully you understand what I am trying to do.

    • @jiejenn
      @jiejenn  4 ปีที่แล้ว

      If you want to process rows based on a condition(s), after the loop, you can insert an IF statement to express your criteria. For example, if your field is called "Processed", the code would look something like
      IF .fieldname("Processed").value = "Yes" THEN
      [mail merge code block]
      END

    • @ScottAlexander68
      @ScottAlexander68 4 ปีที่แล้ว

      @@jiejenn I figured that part out after some trial and error. But what I want it to do is after it finds the records and creates the new documents, update the row in Excel so it does not have a duplicate made. For example, say I have 10 rows and I have a "Processed" column. 4 of the 10 rows have No in this column and 6 have Yes. The query finds the 4 rows that were not processed, your script creates the PDF, but I want those rows to change the No to Yes so next time I run the script, these rows will not be created again. Hope that makes sense.

    • @jiejenn
      @jiejenn  4 ปีที่แล้ว +1

      @@ScottAlexander68 I think I understood your question fully now. If you want to update cells in Excel, it involves of adding Excel reference in Word VBA, which is a bit more advanced if you do not have experience in writing VBA. I will take this as an idea and to make a part 2 video in the future.

    • @ScottAlexander68
      @ScottAlexander68 4 ปีที่แล้ว

      @@jiejenn Don't have much experience at all. That would be great and I am going to do some reading too lol.

  • @michaelmassette5691
    @michaelmassette5691 4 ปีที่แล้ว

    I was able to run this but the word docs and PDF files that were created are blank. any ideas?

    • @jiejenn
      @jiejenn  4 ปีที่แล้ว +1

      This seems to be a common problem. Can you send me your data file and your Word doc that contains the VBA code to TH-cam@LearnDataAnalysis.org.

    • @michaelmassette5691
      @michaelmassette5691 4 ปีที่แล้ว

      Jie Jenn thanks for your reply. I figured out what happened; I forgot to change the name of the worksheet. Your tutorial is extremely helpful. I’m not kidding...what used to take me 4 hours to do now takes me less than 5 minutes. I’m a total noob but getting the hang of it thanks to you. I appreciate your time putting together these tutorials. Very easy to follow and understand.

    • @michaelmassette5691
      @michaelmassette5691 4 ปีที่แล้ว

      Is it possible to add another field to the file name? Let’s say I want the company name to pull from one field but I would also like to include the cost center from another field. The file name should look like this: COMPANY_CC9210. Thanks!!

  • @musav7863
    @musav7863 4 ปีที่แล้ว

    Jie, it was great, it worked first time. now the second document i'm getting all the copies saved by each name instead of individual page. any help?

    • @jiejenn
      @jiejenn  4 ปีที่แล้ว +1

      Can you be more specific? Not sure if I understand your question clearly.

    • @musav7863
      @musav7863 4 ปีที่แล้ว

      @@jiejenn thank you for your reply. i managed to work it out. thank you again. you are great!

    • @jiejenn
      @jiejenn  4 ปีที่แล้ว

      Cool. Glad that you managed to worked it out.

  • @selfreflections3066
    @selfreflections3066 4 ปีที่แล้ว

    Thank You. Lots of blessings for you... This is so powerful.

  • @MalinaC
    @MalinaC 3 ปีที่แล้ว

    Awesome! Thank you!