Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default how to control word from excel

I have never tried to work with VBA controlling two programs. After good
help form MVP and a lot of testing I'm at the level that things start to
work.

I copy an area from excel, open a document in word based on a template and
like to copy the text to a bookmark in the new document in Word. Everything
works until the pasting. I have tried several things - here is my last trial
that does not work.

I think there is an easy answer to this:

Sub åpneword()
Range("adrbedrift").Copy
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim wordwasnotrunning As Boolean
On Error Resume Next

Set oWord = GetObject(, "Word.Application")
If Err Then
Set oWord = New Word.Application
wordwasnotrunning = True
End If

oWord.Visible = True
oWord.Activate
Set oDoc = oWord.Documents.Add("g:\Maler\Excel\Brev som hentes fra
excel.dot")
' oDoc.Range.Text = "hi"

oDoc.Bookmarks("adresse").Select

Selection.PasteSpecial Link:=False, DataType:=wdPasteText, Placement:=
wdInLine, DisplayAsIcon:=False

End Sub




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default how to control word from excel



Since you are running this from Excel, the unqualified Selection will refer
to the selection in Excel. You need to qualify it with the word
application. Assuming this is where you are having a problem.

Sub åpneword()
Range("adrbedrift").Copy
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim wordwasnotrunning As Boolean
On Error Resume Next

Set oWord = GetObject(, "Word.Application")
If Err Then
Set oWord = New Word.Application
wordwasnotrunning = True
End If

oWord.Visible = True
oWord.Activate
Set oDoc = oWord.Documents.Add("g:\Maler\Excel\Brev som hentes fra
excel.dot")
' oDoc.Range.Text = "hi"

oDoc.Bookmarks("adresse").Select

oWord.Selection.PasteSpecial Link:=False, _
DataType:=wdPasteText, Placement:= _
wdInLine, DisplayAsIcon:=False

End Sub

--
Regards,
Tom Ogilvy

"Torstein S. Johnsen" wrote in message
...
I have never tried to work with VBA controlling two programs. After good
help form MVP and a lot of testing I'm at the level that things start to
work.

I copy an area from excel, open a document in word based on a template and
like to copy the text to a bookmark in the new document in Word.

Everything
works until the pasting. I have tried several things - here is my last

trial
that does not work.

I think there is an easy answer to this:

Sub åpneword()
Range("adrbedrift").Copy
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim wordwasnotrunning As Boolean
On Error Resume Next

Set oWord = GetObject(, "Word.Application")
If Err Then
Set oWord = New Word.Application
wordwasnotrunning = True
End If

oWord.Visible = True
oWord.Activate
Set oDoc = oWord.Documents.Add("g:\Maler\Excel\Brev som hentes fra
excel.dot")
' oDoc.Range.Text = "hi"

oDoc.Bookmarks("adresse").Select

Selection.PasteSpecial Link:=False, DataType:=wdPasteText, Placement:=
wdInLine, DisplayAsIcon:=False

End Sub






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
2007 Form Control/ActiveX Control font difference Nikko963 Excel Discussion (Misc queries) 0 April 15th 09 04:21 PM
Excel spin box - no Control tab in Format Control dialong box tocoau Excel Worksheet Functions 7 August 10th 08 03:15 PM
Word wrapping in Text Box Control feature Stilla Excel Worksheet Functions 2 December 7th 05 09:08 PM
Print Control in Word/Excel Charles Maxson Excel Programming 0 December 30th 03 08:55 PM
Print Control in Word/Excel losmac[_2_] Excel Programming 0 December 30th 03 08:22 PM


All times are GMT +1. The time now is 09:47 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"