How to Open Word Excel File in VB

> Edraw Tip > How to Open Word Excel File in VB
author
Posted by James Freeman |
Office Viewer Component allows visual basic developers to open, close, edit, print Word document and Excel workbook inside the VB form.

How to open a shared, read-only MS Word document in MS Word inside of the application upon clicking a command button? The component supports seamless integration with Office 97, Office 2000, Office 2003, Office 2007 and Office 2010.
Edraw Office Viewer Component supports embedding Office documents in your application by implementing a full featured ActiveX document container. Now you can create, open, edit, view and save office documents such as *.doc, *.docx, *.xls, *.xlsx, *.ppt, *.pptx etc in the web page. With Office component you can have Office run embedded inside your custom solution.

Download Office Viewer Component and View Sample Projects

How to Open Word Excel File in VB

1. From the Project Menu select Components...

2. Select control "Edraw Office Viewer Component Module" in the controls table.

3. Click the OK Button.

4. The control will now appear in your toolbox.

5. Drag and drop the control on your form.

6. Right click the control then choose the View Code item.

7. Add the NotifyCtrlReady event and set the library file to load.

Private Sub Command1_Click()
EDOffice1.OpenFileDialog
End Sub

Private Sub Command2_Click()
EDOffice1.SaveFileDialog
End Sub

Private Sub Command3_Click()
If EDOffice1.Toolbars = False Then
EDOffice1.Toolbars = True
Else
EDOffice1.Toolbars = False
End If
End Sub

Private Sub Command4_Click()
If EDOffice1.IsOpened = True Then
If EDOffice1.GetCurrentProgID = "Word.Application" Then
EDOffice1.ProtectDoc wdAllowOnlyFormFields
ElseIf EDOffice1.GetCurrentProgID = "Excel.Application" Then
EDOffice1.ProtectDoc XlProtectTypeNorma
End If
End If
End Sub

Private Sub Command5_Click()
EDOffice1.PrintDialog
End Sub

Private Sub EDOffice1_BeforeDocumentOpened()
''EDOffice1.SetValue "Password", "123"
''EDOffice1.SetValue "WritePassword", "456"
EDOffice1.DisableFileCommand wdUIDisalbeSave, True
EDOffice1.DisableFileCommand wdUIDisalbeSaveAs, True
EDOffice1.DisableFileCommand wdUIDisalbeSaveAsMenu, True
EDOffice1.DisableFileCommand wdUIDisalbePrint, True
EDOffice1.DisableFileCommand wdUIDisalbePrintQuick, True
End Sub

Private Sub EDOffice1_NotifyCtrlReady()
EDOffice1.LicenseName = ""
EDOffice1.LicenseKey = ""
End Sub

8. Run the project.

Open Word, Excel in VB

Support the Office Automation

Disables MS Word Standard Command

Disable Office Ribbon Button

Show/Hide Office Menu Bar

download EdrawMind
main page

Get Started! You Will Love This Easy-To-Use Diagram Software

EdrawMax is an advanced all-in-one diagramming tool for creating professional flowcharts, org charts, mind maps, network diagrams, UML diagrams, floor plans, electrical diagrams, science illustrations, and more. Just try it, you will love it!