Solved

Word 2000 and WordPerfect VB integration

Posted on 2002-04-30
12
274 Views
Last Modified: 2007-12-19
Here is my question.  I need to shell out to either word or word perfect (depending on the user) and save a new document according to what the user typed into the vb app(They type the document name).  Currently I'm using send keys and waiting for the editors to open, when they open I send  the keys the alt F and S then send keys the Document name, then send keys another alt s.  

This process works, but it is ugly.  I dont want to use the send keys.  

Is there anyway to back door into the editors??  So in other words I will shell to the editor, but then instead of using sendkeys to implement the save I use something else.


Any thoughts would be helpful

J.
0
Comment
Question by:jtjcomp
  • 7
  • 4
12 Comments
 
LVL 1

Expert Comment

by:S2
ID: 6981450
Dim WordApp1 As Word.Application

Set WordApp1 = CreateObject("word.application")

and you can continue from here.
0
 
LVL 1

Expert Comment

by:soferstam
ID: 6981485
Sure,
To open word:
Add reference to word type library(or use create object-this is better if you don't know what MSword installed on a client)
Open word:
''''''''''''''''''''''''
Set objWord = New Word.Application
Set ObjDoc = objWord.Documents.Add
(or Set ObjDoc = objWord.Documents.Open(the path))
''''''''''''''''''''''''
To write:
ObjDoc.Sections(1).headers(wdHeaderFooterPrimary).Range.text=""
ObjDoc.Sections(1).headers(wdHeaderFooterFirstPage).Range.text=""
ObjDoc.Sections(1).Footers(wdHeaderFooterFirstPage).Range.text=""
ObjDoc.Sections(1).Footers(wdHeaderFooterPrimary).Range.text=""
ObjDoc.Range.test=""
to close:
''''''''''''''''''''''''
For Each ObjDoc In objWord.Documents
    If Not TypeName(ObjDoc) = "Nothing" Then
    ObjDoc.Close False
    Set ObjDoc = Nothing
    End If
Next
''''''''''''''''''''''''
And,if you don't know the word object module,you can alway's record macro in word and copy this code into your vb application:
1.Start record macro.
2.Do in word whatever you have to de
3.Stop recording and go to VBA editor.
4.Copy this code into your vb procedure.

To save in different formats:
ObjDoc.SaveAs FileName:=SaveTo, fileformat:=wdFormatDocument

Search for Q235928 for supported file formats
0
 
LVL 1

Expert Comment

by:soferstam
ID: 6981519
More about formats:
To save word in defferent formats,you have to:
1.Install this format by open a new docoment and trying to save it in format you wish.It will install automatically file converter.
2.Use know constants :
"wdFormatDocument"
"wdFofmatDOSText"
"wdFormatDOSTextLineBreaks"
"wdFormatEncodedText"
"wdformathtml"
"wdformatrtf"
"wdFormatRTF"
"wdformattemplate"
"wdformattext"
"wd"wdFormatUnicodeText"
"formattextlinebreaks"
Example:
ObjDoc.SaveAs FileName:=SaveTo, fileformat:=wdFormatDocument


Or,use class names:
CnvClassName="wrdprfctdos51"
MyPath="" 'without extention !
     For Each FCnv In objWord.FileConverters
      If Trim(LCase(FCnv.ClassName)) = Trim(LCase(CnvClassName)) Then
      On Error Resume Next
      MyPath=PyPath & "." & FCnv.Extensions
      ObjDoc.SaveAs FileName:=MyPath, fileformat:=FCnv.SaveFormat
           If Err.Number <> 0 Then

               End If
      End If
      Next
0
 
LVL 1

Expert Comment

by:soferstam
ID: 6981529
Sorry,to busy with something else..
This is possible class names you can use.
You can find much more info on msdn.
 
MS-DOS Text with Layout
 MS-DOS Text with Layout
 
Text with Layout
 Text with Layout
 
Word 2.x for Windows
 MSWordWin2
 
Word 4.0 for Macintosh
 MSWordMac4
 
Word 5.0 for Macintosh
 MSWordMac5
 
Word 5.1 for Macintosh
 MSWordMac51
 
WordPerfect 5.0
 WrdPrfctDOS50
 
WordPerfect 5.1 for DOS
 WrdPrfctDOS51
 
WordPerfect 5.x for Windows
 WrdPrfctWin
 
WordPerfect 5.1 or 5.2 Secondary File
 WrdPrfctDat
 
WordPerfect 5.0 Secondary File
 WrdPrfctDat50
 
Works 4.0 for Windows
 MSWorksWin4
 
Word 6.0/95
 MSWord6Exp
 
Word 97-2000 & 6.0/95 - RTF
 MSWord6RTFExp
 
0
 
LVL 1

Author Comment

by:jtjcomp
ID: 6981556
soferstam

I'm trying your code now to open the word editor.  I have set my references and added the following lines

Dim WordApp As New Word.Application
Dim WPApp As New WordPerfect.Application

Set WordApp = CreateObject("word.application")
Set WordDoc = WordApp.Documents.Add

When I run through this in code, WinWord.exe shows up in the taskmanager but the window does not open and I can not find it anywhere on the desktop.  I'm I missing something
0
 
LVL 1

Expert Comment

by:soferstam
ID: 6981564
Yes,sorry..
You must make it visible:
objWord.Visible = True
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:jtjcomp
ID: 6981568
soferstam

I'm trying your code now to open the word editor.  I have set my references and added the following lines

Dim WordApp As New Word.Application
Dim WPApp As New WordPerfect.Application

Set WordApp = CreateObject("word.application")
Set WordDoc = WordApp.Documents.Add

When I run through this in code, WinWord.exe shows up in the taskmanager but the window does not open and I can not find it anywhere on the desktop.  I'm I missing something
0
 
LVL 1

Author Comment

by:jtjcomp
ID: 6981572
Ok, so now I see the editor, but there is not a wordapp.save method or is there?  I know the name of the document I just need to do a save for it when the editor opens.

J
0
 
LVL 1

Author Comment

by:jtjcomp
ID: 6981592
But after the save I want to leave the editor open
0
 
LVL 1

Expert Comment

by:soferstam
ID: 6981605
ObjDoc.Activate
ObjDoc.Save  or .saveas ....
Is that the question?
0
 
LVL 1

Accepted Solution

by:
soferstam earned 100 total points
ID: 6981607
The editor will remaining open after the save
0
 
LVL 1

Expert Comment

by:soferstam
ID: 6981685
You will leave the editor open,
but sometime you still need to close it.
Make sure you completely close it,as follows:


For Each ObjDoc In objWord.Documents
   If Not TypeName(ObjDoc) = "Nothing" Then
   ObjDoc.Close False
   Set ObjDoc = Nothing
   End If
Next
If Not TypeName(objWord) = "Nothing" Then
  If objWord.Documents.Count = 0 Then objWord.Quit False
  Set objWord = Nothing
End If

Good luck!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now