Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Word 2000 and WordPerfect VB integration

Posted on 2002-04-30
12
Medium Priority
?
315 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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 400 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

636 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