Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel to open word document -basics


I am trying to insert some excel data into a word doc & have never done
this before (and still a newbie at VBA). In order to get started I
have been playing at getting the basics right.

Have set up bookmarks in the Word doc ("test") called "customer" and
"solution". I have set up a commandbutton on the worksheet to open the
word document. When the commandbutton is activated, apart from opening
the word document, I want the document to automatically insert text
into the word doc.

Have used the following code:

Sub Commandbutton6_Click()

Dim wdApp As Word.Application
Dim wdDoc As Document
Dim wdRng As Word.Range

Set wdApp = New Word.Application
Set wdDoc = wdApp.Documents.Open("C:\test")
wdApp.Visible = True

Dim myArray()
Dim wdBkmk As String

myArray = Array("customer", "solution")

SetwdRng = wdApp.ActiveDocument.Bookmarks(myArray(0)).Range
wdRng.InsertBefore ("test")

SetwdRng = wdApp.ActiveDocument.Bookmarks(myArray(1)).Range
wdRng.InsertBefore ("test again")


SetwdApp = Nothing
SetwdRng = Nothing

End Sub

The document opens ok, but keep getting an error:

"Runtime 91 error - Object variable or With block variable no set"

Tried many things without success -any help on this to get me started
with the basics would be most appreciated.




Cheers

Peter


--
peter.thompson
------------------------------------------------------------------------
peter.thompson's Profile: http://www.excelforum.com/member.php...o&userid=29686
View this thread: http://www.excelforum.com/showthread...hreadid=499647

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 292
Default Excel to open word document -basics

Hi

Try
Set wdRng
instead of SetwdRng.

HTH. Best wishes Harald

"peter.thompson"
<peter.thompson.21eqaq_1136877015.9814@excelforu m-nospam.com skrev i
melding news:peter.thompson.21eqaq_1136877015.9814@excelfo rum-nospam.com...

I am trying to insert some excel data into a word doc & have never done
this before (and still a newbie at VBA). In order to get started I
have been playing at getting the basics right.

Have set up bookmarks in the Word doc ("test") called "customer" and
"solution". I have set up a commandbutton on the worksheet to open the
word document. When the commandbutton is activated, apart from opening
the word document, I want the document to automatically insert text
into the word doc.

Have used the following code:

Sub Commandbutton6_Click()

Dim wdApp As Word.Application
Dim wdDoc As Document
Dim wdRng As Word.Range

Set wdApp = New Word.Application
Set wdDoc = wdApp.Documents.Open("C:\test")
wdApp.Visible = True

Dim myArray()
Dim wdBkmk As String

myArray = Array("customer", "solution")

SetwdRng = wdApp.ActiveDocument.Bookmarks(myArray(0)).Range
wdRng.InsertBefore ("test")

SetwdRng = wdApp.ActiveDocument.Bookmarks(myArray(1)).Range
wdRng.InsertBefore ("test again")


SetwdApp = Nothing
SetwdRng = Nothing

End Sub

The document opens ok, but keep getting an error:

"Runtime 91 error - Object variable or With block variable no set"

Tried many things without success -any help on this to get me started
with the basics would be most appreciated.




Cheers

Peter


--
peter.thompson
------------------------------------------------------------------------
peter.thompson's Profile:
http://www.excelforum.com/member.php...o&userid=29686
View this thread: http://www.excelforum.com/showthread...hreadid=499647



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default Excel to open word document -basics

Incidentally, this kind of typo will be caught by the compiler if
you use Option Explicit. Set "Require Variable Declaration" in
Tools/Options from the VBA window to ensure it's there
by default . (And while you're in there, you might want to turn
off the annoying "Auto Syntax Check"..)

Harald Staff wrote:
Hi

Try
Set wdRng
instead of SetwdRng.

HTH. Best wishes Harald

"peter.thompson"
<peter.thompson.21eqaq_1136877015.9814@excelforu m-nospam.com skrev i
melding news:peter.thompson.21eqaq_1136877015.9814@excelfo rum-nospam.com...

I am trying to insert some excel data into a word doc & have never done
this before (and still a newbie at VBA). In order to get started I
have been playing at getting the basics right.

Have set up bookmarks in the Word doc ("test") called "customer" and
"solution". I have set up a commandbutton on the worksheet to open the
word document. When the commandbutton is activated, apart from opening
the word document, I want the document to automatically insert text
into the word doc.

Have used the following code:

Sub Commandbutton6_Click()

Dim wdApp As Word.Application
Dim wdDoc As Document
Dim wdRng As Word.Range

Set wdApp = New Word.Application
Set wdDoc = wdApp.Documents.Open("C:\test")
wdApp.Visible = True

Dim myArray()
Dim wdBkmk As String

myArray = Array("customer", "solution")

SetwdRng = wdApp.ActiveDocument.Bookmarks(myArray(0)).Range
wdRng.InsertBefore ("test")

SetwdRng = wdApp.ActiveDocument.Bookmarks(myArray(1)).Range
wdRng.InsertBefore ("test again")


SetwdApp = Nothing
SetwdRng = Nothing

End Sub

The document opens ok, but keep getting an error:

"Runtime 91 error - Object variable or With block variable no set"

Tried many things without success -any help on this to get me started
with the basics would be most appreciated.




Cheers

Peter


--
peter.thompson
------------------------------------------------------------------------
peter.thompson's Profile:
http://www.excelforum.com/member.php...o&userid=29686
View this thread: http://www.excelforum.com/showthread...hreadid=499647


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel to open word document -basics


Thanks for the help and tips guys -now works fine!

Cheers

Peter


--
peter.thompson
------------------------------------------------------------------------
peter.thompson's Profile: http://www.excelforum.com/member.php...o&userid=29686
View this thread: http://www.excelforum.com/showthread...hreadid=499647

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
excel trying to open word document tina Excel Discussion (Misc queries) 2 April 19th 07 02:16 PM
open word document in excel spaceslime Excel Discussion (Misc queries) 1 August 13th 05 03:15 PM
what happens if I open an excel document in word? Emily Excel Discussion (Misc queries) 3 April 2nd 05 10:49 AM
open up a word document in excel [email protected] Excel Programming 1 December 23rd 04 04:43 PM
open a word document in excel Herb[_4_] Excel Programming 1 August 9th 03 01:36 AM


All times are GMT +1. The time now is 03:40 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"