Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Writing a Word doc from Excel

In Excel 2000, I can write a Word document without a problem. However, my
code to write the doc is in a separate routine. I need to enter this routine
several times to print any errors found in my editing. The first time in I
can create the Word object, write the headings, write the error msg (even
create a footer). The second time in (all subsequent times), I can bypass
the 'create the word object' and bypass the writing of the header. BUT, the
new error message does not write. Do I need to reestablish the connection to
the word object? Or what else can be wrong?

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Writing a Word doc from Excel

Post the code you are using.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Sheldon" wrote in message
...
In Excel 2000, I can write a Word document without a problem.
However, my
code to write the doc is in a separate routine. I need to
enter this routine
several times to print any errors found in my editing. The
first time in I
can create the Word object, write the headings, write the error
msg (even
create a footer). The second time in (all subsequent times), I
can bypass
the 'create the word object' and bypass the writing of the
header. BUT, the
new error message does not write. Do I need to reestablish the
connection to
the word object? Or what else can be wrong?

Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Writing a Word doc from Excel

Here is the code

Public Sub PrintErrorReportToWord(strErrorMsg As String)

On Error Resume Next

If gblnErrRptStarted = False Then
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

.Selection.Font.Bold = True
.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Selection.Font.Size = 16
.Selection.TypeText "Error Report for"
.Selection.typeparagraph
.Selection.Font.Size = 12
.Selection.TypeText gstrConfigFile
.Selection.Font.Bold = False
.Selection.typeparagraph
.Selection.TypeText " "
.Selection.typeparagraph
.Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
.Selection.Font.Bold = False
.Selection.Font.Size = 8
.Selection.TypeText " " & Now()
.Selection.typeparagraph
.Selection.TypeText " "
.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
.Selection.Font.Size = 12
.Selection.typeparagraph
.Selection.TypeText " "
.Selection.typeparagraph

End With

gblnErrRptStarted = True
End If

With wdApp

.Selection.TypeText " "
.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
.Selection.Font.Size = 10
.Selection.typeparagraph
.Selection.TypeText strErrorMsg
.Selection.typeparagraph

End With

AddFooter wdApp

Set wdApp = Nothing

End Sub

"Chip Pearson" wrote:

Post the code you are using.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Sheldon" wrote in message
...
In Excel 2000, I can write a Word document without a problem.
However, my
code to write the doc is in a separate routine. I need to
enter this routine
several times to print any errors found in my editing. The
first time in I
can create the Word object, write the headings, write the error
msg (even
create a footer). The second time in (all subsequent times), I
can bypass
the 'create the word object' and bypass the writing of the
header. BUT, the
new error message does not write. Do I need to reestablish the
connection to
the word object? Or what else can be wrong?

Thanks




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Writing a Word doc from Excel

Get rid of the following line of code:
Set wdApp = Nothing

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Sheldon" wrote in message
...
Here is the code

Public Sub PrintErrorReportToWord(strErrorMsg As String)

On Error Resume Next

If gblnErrRptStarted = False Then
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

.Selection.Font.Bold = True
.Selection.ParagraphFormat.Alignment =
wdAlignParagraphCenter
.Selection.Font.Size = 16
.Selection.TypeText "Error Report for"
.Selection.typeparagraph
.Selection.Font.Size = 12
.Selection.TypeText gstrConfigFile
.Selection.Font.Bold = False
.Selection.typeparagraph
.Selection.TypeText " "
.Selection.typeparagraph
.Selection.ParagraphFormat.Alignment =
wdAlignParagraphRight
.Selection.Font.Bold = False
.Selection.Font.Size = 8
.Selection.TypeText " " & Now()
.Selection.typeparagraph
.Selection.TypeText " "
.Selection.ParagraphFormat.Alignment =
wdAlignParagraphLeft
.Selection.Font.Size = 12
.Selection.typeparagraph
.Selection.TypeText " "
.Selection.typeparagraph

End With

gblnErrRptStarted = True
End If

With wdApp

.Selection.TypeText " "
.Selection.ParagraphFormat.Alignment =
wdAlignParagraphLeft
.Selection.Font.Size = 10
.Selection.typeparagraph
.Selection.TypeText strErrorMsg
.Selection.typeparagraph

End With

AddFooter wdApp

Set wdApp = Nothing

End Sub

"Chip Pearson" wrote:

Post the code you are using.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Sheldon" wrote in message
...
In Excel 2000, I can write a Word document without a
problem.
However, my
code to write the doc is in a separate routine. I need to
enter this routine
several times to print any errors found in my editing. The
first time in I
can create the Word object, write the headings, write the
error
msg (even
create a footer). The second time in (all subsequent
times), I
can bypass
the 'create the word object' and bypass the writing of the
header. BUT, the
new error message does not write. Do I need to reestablish
the
connection to
the word object? Or what else can be wrong?

Thanks






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
Writing Macro in Excel 07 Tony Excel Worksheet Functions 3 July 4th 09 02:11 AM
Writing Excel Macro McHarrisco Excel Worksheet Functions 1 November 30th 05 09:28 PM
Help writing an Excel Formula bella0711 Excel Worksheet Functions 4 September 9th 05 03:57 PM
Writing to Excel using ASP.NET timothym Excel Programming 5 December 12th 03 01:06 PM
opening & writing to Word from Excel Mike Molyneaux[_2_] Excel Programming 2 October 21st 03 04:58 PM


All times are GMT +1. The time now is 02:16 PM.

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"