Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Writing Macro in Excel 07 | Excel Worksheet Functions | |||
Writing Excel Macro | Excel Worksheet Functions | |||
Help writing an Excel Formula | Excel Worksheet Functions | |||
Writing to Excel using ASP.NET | Excel Programming | |||
opening & writing to Word from Excel | Excel Programming |