Solved

Handling MS-Office Components in VB

Posted on 2002-07-05
5
217 Views
Last Modified: 2010-05-18
I want to have a full control on MS Office Components (Word, Excel) through my VB program. Though one can "execute" external application using
wd as Word.Application
Set wd = new Word.Application
wd.visible = true

but actually it just opens the application in another (external) window, and I want to know whether one can get the Word/Excel application right on the VB form or something similer that can be controlled through VB code (actually i want to control the SAVE, SAVE AS & OPEN feature and rest the things should be handled by Word/Excel itself).

I've seen something similar with WordPad. Its object can be inserted directly on the form. but it is NOT visible on the form during runtime untill doubleclicked on that area, and then it acts just as WordPad on our form, even with all its meus & options except [File] menu.

One more thing, can the document such opened/created through VB form (in word/excel) can be stored "AS IT IS" in any Database(SQL/Oracle)?

My objective is to let the user of my application the facility of WORD/EXCEL within my application and the documents should be stored in database table insted of DOC or XLS file.

Hope somebody's there to help me out!
0
Comment
Question by:vijaywadnere
5 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7132695
If not XP:
' general declarations section
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long


'form load or after Word was instantiated:

    ' reparent the window to fit our form
    Dim ret As Long
    ret = FindWindow("Opusapp", vbNullString)
    SetParent ret, Me.hWnd
0
 

Author Comment

by:vijaywadnere
ID: 7133703
Richie,
I tried the code supplied by you but it wont work.
I do not understand how FindWindow funciton will come to know about the Word application. I also tried as :

set wd = new Word.Application
dim ret as long
ret = FindWindow( wd.name, vbNullString)
setParent ret, Me.hWnd

but found not running properly. the value returned by the FindWindow in both the cases is "0".

what should be the name of class supplied in FindWindow function? It might have some relation with the word application object, isn't it?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7138374
Opussapp is the class name for Word. Wd.name isn't usefull here.
Try this:

set wd = new Word.Application
wd.visible =true
dim ret as long
ret = FindWindow( "Opusapp", vbNullString)
if ret <>0 then
  setParent ret, Me.hWnd
end if

' if you know the name of document in advance, you coul dreplace vbnullstring with "Microsoft Word - " & <document name here>

I used that code a million of times with no problem.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7990754
Hi vijaywadnere,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Refund points and save as a 0-pt PAQ.
    *** actual question (control SAVE, etc.) not answered

vijaywadnere, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 8053110
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

707 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

20 Experts available now in Live!

Get 1:1 Help Now