Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default opening & writing to Word from Excel

I'm running Excel & Word 2000 on nt4, sp6

I'm trying to create a mailmerge file from Excel with data
from the excel sheet.

I get a 'variable not defined' compiler error on
the 'wdMailingLabels' value of
the '.ActiveDocument.MailMerge.MainDocumentType = ' line.

I expect similar compile errors on other values. How can I
find what I need to code these in order to execute the
macro?


Dim wordApp As Object
Set wordApp = CreateObject("Word.Application")

With wordApp

.ActiveDocument.MailMerge.MainDocumentType =
wdMailingLabels

End With

wordApp.Quit
Set wordApp = Nothing


thanks for any help



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default opening & writing to Word from Excel

In Word, you can type a question mark and constant name in the Immediate
window, e.g.:
?wdMailingLabels

then press the Enter key, to determine the value of the constant.

In Excel, list the constants at the top of the module, and the code
should run correctly:

'================================
Option Explicit
Const wdMailingLabels As Long = 1

Sub MergeDoc()
Dim WdApp As Object

Selection.Copy
On Error Resume Next
Set WdApp = GetObject(, "Word.Application")
If Err.Number < 0 Then
Err.Clear
Set WdApp = CreateObject("Word.Application")
End If

With WdApp
.Visible = True
.Documents.Add DocumentType:=0
.ActiveDocument.MailMerge.MainDocumentType _
= wdMailingLabels
End With
' Set WdApp = Nothing

End Sub
'==========================

Mike Molyneaux wrote:
I'm running Excel & Word 2000 on nt4, sp6

I'm trying to create a mailmerge file from Excel with data
from the excel sheet.

I get a 'variable not defined' compiler error on
the 'wdMailingLabels' value of
the '.ActiveDocument.MailMerge.MainDocumentType = ' line.

I expect similar compile errors on other values. How can I
find what I need to code these in order to execute the
macro?


Dim wordApp As Object
Set wordApp = CreateObject("Word.Application")

With wordApp

.ActiveDocument.MailMerge.MainDocumentType =
wdMailingLabels

End With

wordApp.Quit
Set wordApp = Nothing


thanks for any help





--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default opening & writing to Word from Excel


Thank you thank you thank you
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
Opening word docs in excel doss04 Excel Discussion (Misc queries) 3 October 4th 08 06:54 PM
Opening a Word Template from within Excel perry Excel Worksheet Functions 0 January 30th 07 12:23 PM
Opening a Word Document in Excel Tonja Excel Programming 2 September 18th 03 02:56 AM
opening and writing into notepad peter Excel Programming 1 August 15th 03 07:09 PM


All times are GMT +1. The time now is 05:36 AM.

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

About Us

"It's about Microsoft Excel"