Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Copy cells from excel to word bookmarks
I have a list of people with characteristics (Name, Age, Address...) that I'm creating on excel. I want to be able to select a cell, click a button and:
* open a word template
* populate it's bookmarks
* save it with the person's name
* return to the excel workbook
I've pretty much patched up the code to function but I'm running into an interesting problem: the code breaks exactly once in every two times during
[code]ActiveDocument.SaveAs Filename:=SavePath & Name & ".doc"[/code]
with Run-time error '462': The remote server machine does not exist or is unavailable.
This is the code:
SavePath = Worksheets("Sheet2").[B3]
TemplatePath = Worksheets("Sheet2").[B6]
Dim Name As String
Dim wrdApp As Word.Application
Set wrdApp = CreateObject("Word.Application")
Name = Selection.Value
Application.ScreenUpdating = False
.Selection.GoTo What:=wdGoToBookmark, Name:="Name"
.Visible = True
ActiveDocument.SaveAs Filename:=SavePath & Name & ".doc" 'WORKS!!
Application.CutCopyMode = False
Application.ScreenUpdating = True
MsgBox ("File successfully created for " & Selection.Value & "!")
I'm new with VBA programming. The way I manage is by hacking other people's codes and patching it all up (often using cellotape) to achieve my goals. I'm hoping this will explain inconsistencies on my code...
I also welcome any hints, tips and suggestions in general =)
I noticed a zillion different ways of accomplishing this and am open to getting one of those to work.
Thank you for your time and attention!
0 · ·