Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

Handling MS-Office Components in VB

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
vijaywadnere
Asked:
vijaywadnere
1 Solution
 
Richie_SimonettiCommented:
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
 
vijaywadnereAuthor Commented:
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
 
Richie_SimonettiCommented:
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
 
DanRollinsCommented:
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
 
SpideyModCommented:
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now