Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Troubles with Excel in VB6. 1

Status
Not open for further replies.

elmorro

Programmer
Jun 23, 2005
133
0
0
US
I have written an ap in VB6 that opens up an Excel spreadsheet as read only, because I don't want anyone to overwrite the file. I also don't want anyone to use the Save As feature to save the file somewhere else. Is there a way to lock the file or just prevent the users from using the Save As feature?

Here is the code I have so far:

Dim objQuote As Excel.Application
Dim objWorkBook As Excel.Workbook
Dim objWorkSheet As Excel.Worksheet
Set objQuote = New Excel.Application
Set objWorkBook = objQuote.Workbooks.Open("C:\File1.xls", , True)
objQuote.Visible = True

Thanks in advance,
elmorro :)
 
its a bit of a hack, but you could try.

Code:
Dim WithEvents objQuote As Excel.Application
Dim objWorkBook As Excel.Workbook
Dim objWorkSheet As Excel.Worksheet

Private Sub OpenFile()
Set objQuote = New Excel.Application
Set objWorkBook = objQuote.Workbooks.Open("C:\File1.xls", , True)
objQuote.Visible = True
end sub

Private Sub objQuote_WorkbookBeforeSave(ByVal Wb As Excel.Workbook, ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Cancel = True
End Sub

good luck

If somethings hard to do, its not worth doing - Homer Simpson

too much 49374'ing, im 57005... need 12648430
 
ADoozer,
Thanks for your feedback. I will try it and see how it goes.

elmorro :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top