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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel checks, if specific Access program runs

Status
Not open for further replies.

georgp

Technical User
Mar 28, 2002
96
US
Hi there,
I have an Access Application ("A") which calls an Excel application ("E"). I do not want that "E" is opened 'manually', but only by "A".
In other words, the Workbook_Open procedure in "E" should check, if "A" is calling it. If so, "E" should run, otherwise terminate itself.
Any simple suggestion for this? I have used the UserControl function, but it does not work correctly.
Thanks for any advice or help,
GeorgP
 
Do you want to not be albe to open a specific file without accesss or excell in general?
 
Correct.
The excel file should open only, if called by the required (a specified)access file.
I have not solved the problem yet, so thanks for your thoughts...
GeorgP
 
One more comment:
A possible scenario could be that the Excel file is password protected, and the password would be included in the Access procedure to open this Excel file, so that a user is not aware that the Excel file is actually protected, unless he tries to open the file manually.
Any other solution is also welcome.
Thanks, GeorgP
 
Couple ways I can think of to do this. One is to do like you said and password protect it. Another is to place a macro on the document to check for access. I think the easiest and best way would be to use the password. You could use automation to open the document. Something like this:

With Excel.Application
.Workbooks.Open FILENAME:="c:\windows\desktop\book1.xls", Password:="stuff", WriteResPassword:="stuff"
.Visible = True
.ActiveWorkbook.Unprotect Password:="stuff"
End With
 
Thanks a lot.
Actually, I have already defined a certain code, which runs well and is posted below.
The first procedure opens the second, which calls the Excel application (and at the same time checks, if Excel was already running and makes a related entry in a database to either close Excel or keep).
I would like to know, if/how the password can be included in the GetObject or CreateObject statements?

Private Sub cmd01_Click()
'Purpose: Call for Excel opening program from a commad button

'Call Statusbar text change
Call bss_StatusBarSet("Initializing EXCEL ....")

'Calls the excel opening procedure below
Call bss_ProgOpen(SelProgComp:="C:\My Documents\" _& "xxxexcelxxx.xls", SelName:="xxxexcelxxx.xls")

Call bss_StatusBarClear

End Sub

Sub bss_ProgOpen(SelProgComp As String, SelName As String)
' Purpose: Open Excel program

Const cstrProc As String = "bss_ProgOpen"
Dim DB1 As Database
Dim RS1 As Recordset

On Error GoTo bss_ProgOpen_Click_err

Dim objxl As Object

Set DB1 = CurrentDb
Set RS1 = DB1.OpenRecordset("xxxAccessxxx", dbOpenDynaset)
' Update database if or if not Excel is running
RS1.MoveFirst
RS1.Edit

Call bss_StatusBarSet("Starting DUV_Formulations.xls ....")

''''''HOW CAN I INCLUDE PASSWORD HERE?

'bss_fIsAppRunning is a boolean function which checks, if _ Excel is running or not. If so then GETOBJECT else _ CREATEOBJECT with entry in database

If bss_fIsAppRunning("Excel") Then
Set objxl = GetObject(SelProgComp, "Excel.Sheet")
RS1!ExcelRun = "True"
Else
Set objxl = CreateObject("Excel.Application")
Set objxl = GetObject(SelProgComp, "Excel.Sheet")
RS1!ExcelRun = "False"
End If



RS1.Update
RS1.Close

Set RS1 = Nothing
Set DB1 = Nothing

'Now handing over to EXCEL window/application

objxl.Application.UserControl = True
objxl.Application.Visible = True
objxl.Application.Windows(SelName).Visible = True

'Special Excel procedure in the excel program

objxl.Application.Run "ocp_GetStart"

Set objxl = Nothing

bss_ProgOpen_Exit:
Exit Sub

' Some special error handling - not critical

bss_ProgOpen_Click_err:
'Err.Number [287] indicates rejection of Ecxel due to macros
If Err.Number = 287 Then Resume bss_ProgOpen_Exit
Call bss_ErrMsgStd(mcstrMod & "." & cstrProc, Err.Number, Err.Description, True)
Resume bss_ProgOpen_Exit

End Sub

Thanks, GeorgP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top