Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Copy cells from excel to word bookmarks

ephebusephebus Member Posts: 1
Hi there,

The situation:
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:

[code]Sub copyToWord()

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

With wrdApp
.Documents.Open TemplatePath
.Selection.GoTo What:=wdGoToBookmark, Name:="Name"
.Selection.PasteSpecial DataType:=wdPasteText
.Visible = True
ActiveDocument.SaveAs Filename:=SavePath & Name & ".doc" 'WORKS!!
End With

Application.CutCopyMode = False
Application.ScreenUpdating = True

MsgBox ("File successfully created for " & Selection.Value & "!")
End Sub[/code]

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!
Sign In or Register to comment.