Embed Excel in VB 6 and Automating Excel
With PDF viewer component, it's easy for the vb developers to embed an existing pdf files in a form then disable the print, save and copy functions.
At form load event the developers can use the LoadFile method to load pdf files from the hard drive or server and open in an area on the form. The PDF file can be read-only, full edited, or prohibited to save by different requirements. The developers can also change the pdf display options easily with the vb 6 component.
Click Here to Download PDF Viewer Component - Support vb6, vb.net project
Display PDF Files in VB 6 Form
In this part, we will show the detailed sample code on how to create and customize PDF document windows in VB 6 class. But before this, please make sure that you have embedded PDF Viewer Component into your created VB 6 desktop application.
If you haven't the pdfviewer.ocx file, you need to install the package firstly.
Start Visual Basic and create a new standard project. Form1 is created by default.
Right click on any of the tabs in your toolbox and click choose items.
In the pop up dialog, check the PDF Viewer Component.
Click the Ok button.
The PDF Viewer Component was added in the Toolbar window.
Switch to a VB 6 form, then add the component in it.
The component includes lots of methods, events and properties to customize the Adobe Reader window.
The developer can use the following code to open a pdf file in the Form_Load Event.
Private Sub OpenPDF_Click()
.DefaultExt = "pdf"
.Filter = "PDF File Formats (*.pdf)|*.pdf|All Files (*.*) | *.* ||"
.FilterIndex = 1
To protect the Excel worksheet from modification by the end user, the developer needs to add the following code in the DocumentOpened event.
Private Sub EDOffice_DocumentOpened()
EDOffice1.ProtectDoc 1 ' XlProtectTypeNormal
There are some wrapped excel automation methods available to create or modify Excel data.
bool ExcelAddWorkSheet(long Index);
bool ExcelDeleteWorkSheet(long Index);
bool ExcelActivateWorkSheet(long Index);
bool ExcelSetCellValue(long Column, long Row, BSTR Value);
BSTR ExcelGetCellValue(long Column, long Row);
bool ExcelSetRowHeight(long Row, double Height);
bool ExcelSetColumnWidth(long Column, double Width);
afx_msg bool ExcelDeleteRow(long Row);
bool ExcelDeleteColumn(long Column);
bool ExcelInsertRow(long Row);
bool ExcelInsertColumn(long Column);
bool ExcelInsertPageBreakInRow(long Row);
bool ExcelInsertPageBreakInColumn(long Column);
bool ExcelPasteStringToWorksheet(BSTR bstText);
Disable Adobe Reader Edit Function from Visual Basic
In the code window for Form1, insert the following code:
Private Sub DisableAdobeReader_Click()
Press F5 to run the project. The pdf file will be open in the vb 6 window. The user can not changed or copy the pdf files.
With the PDF viewer component, you are not only able to view PDF documents, but also able to disable print, disable copy, disable edit and change the pdf window options.