Please help

Dejan

New Member
Joined
Oct 18, 2002
Messages
24
Two questions?

1. Here is macro that determins if workbook is already opened, but it doesn't work. can somebody help me to make it work?

2. Workbook opens depending on cell value -> Workbooks.Open FileName:= _
("D:Dreid" & Sheets("Radne knjige").Range("B1").Value).
Each workbook has Auto_Open macro that should open a certan userform (each workbook a diferent one). When workbook opens nothing hapens. I've tried "Application.Run (Sheets("Radne knjige").Range("B1").Value)!Auto_Open)" but it has only laught at me.

Here is whole macro:


Function bFileOpen(wbName As String) As Boolean
Dim wb As Workbook
'check each open workbook's name, in lower case, and set the function
'to true if a match is found. If not match the function defaults to False
For Each wb In Workbooks
If LCase(wb.Name) = LCase(wbName) Then
bFileOpen = True
Exit Function
End If
Next
End Function

Sub provjera()
Application.ScreenUpdating = False
If bFileOpen("D:Dreid" & Sheets("Radne knjige").Range("B1").Value) Then
Exit Sub
End If


If Not bFileOpen("D:Dreid" & Sheets("Radne knjige").Range("B1").Value) Then

ChDir "D:Dreid"
Workbooks.Open FileName:= _
("D:Dreid" & Sheets("Radne knjige").Range("B1").Value)
Application.Run "Auto_Open"

Workbooks("Dreid.xls").Save
Workbooks("Dreid.xls").Close
End If
End Sub



THNX
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
1. You only need to pass the name of your workbook to the Function, not the full path, eg "Book2.xls". Or use the FullName property instead of the Name property in your Function.

2. You need to use the RunAutoMacros Method to run your Auto_Open procedure, like this:

ActiveWorkbook.RunAutoMacros xlAutoOpen
 

Richie(UK)

MrExcel MVP
Joined
May 17, 2002
Messages
3,329
Hi Dejan,

You may find this function useful re open workbooks:
http://www.erlandsendata.no/english/vba/wb/wbisopen.htm

As regards your auto-open query, have you considered using the Workbook_Open event of the workbooks concerned instead? (Auto-open is, I understand, only really retained for backwards compatability with older versions of Excel).

HTH
 

Forum statistics

Threads
1,143,748
Messages
5,720,625
Members
422,293
Latest member
camillel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top