Advertisement

05.14.2008 at 09:23AM PDT, ID: 23402093
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Help in rewriting function to open linked workbook

Tags: Excel, 2000
Hi all:

An expert provided the attached function a few months ago.  It works great on my machine for my development purposes but isn't doing what I need it to do when I move things to the server.

Setup: In a directory on the server I have a few quoting workbooks that link to the materials.xls workbook.  All workbooks are set read only in the OS properties to prevent accidental saving of entered data.

Desired:  User1 opens up quote1.xls, which then automatically opens materials.xls.  The user may need to edit values in materials only for these quotes [changes will not be saved].  User1 opens quote2.xls which sees that materials.xls is already open & skips the attempt to open materials.xls.  User2 opens quote2.xls, which then opens materials.xls.  Here I do not need to suppress the dialogs from the OS stating User1 is using the files & do they want to open a read only copy.  The OS would then open an original copy of materials.xls for User2.

Problems:
a]  If materials.xls is set to read only by the OS properties, the current function does not open materials.xls
b]  If I don't use the existing function but instead open materials.xls with

Workbooks.Open Filename:=fileToOpen

the user is presented with a dialog to either re-open materials.xls [which will lose the temporary changes that may have been made] or sends them into VBA debug mode because the file is already open.
c]  Using the existing function; if User2 opens a quote workbook while User1 also has a quote workbook open, the function recognizes materials.xls is in use and therefore materials.xls is not opened.

Thanks in advance for your help.

Bob
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
Private Sub Workbook_Open()
  Application.WindowState = xlMaximized
  Dim wb As Workbook
  Set wb = ThisWorkbook  
  Dim openPath As String
  Dim fileToOpen As String  
  openPath = ThisWorkbook.Path
  fileToOpen = openPath & "\Materials.xls"  
  If IsFileOpen(fileToOpen) Then
    'do nothing
  Else
    Workbooks.Open Filename:=fileToOpen
  End If
  wb.Worksheets("Start").Activate
End Sub
 
Function IsFileOpen(strFullPathFileName As String) As Boolean
  Dim hdlFile As Long
  '// Error is generated if you try
  '// opening a File for ReadWrite lock >> MUST BE OPEN!
  On Error GoTo FileIsOpen:
    hdlFile = FreeFile
    Open strFullPathFileName For Random Access Read Write Lock Read Write As hdlFile
    IsFileOpen = False
    Close hdlFile
    Exit Function
FileIsOpen:
    '// Someone has it open!
    IsFileOpen = True
    Close hdlFile
End Function
Start your free trial to view this solution
Question Stats
Zone: Software
Question Asked By: lynx20
Solution Provided By: RobSampson
Participating Experts: 1
Solution Grade: B
Views: 0
Translate:
Loading Advertisement...
05.14.2008 at 11:25PM PDT, ID: 21571020

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.15.2008 at 08:00AM PDT, ID: 21574371

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.15.2008 at 02:20PM PDT, ID: 21578078

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.15.2008 at 03:06PM PDT, ID: 21578361

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.15.2008 at 03:13PM PDT, ID: 21578397

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.15.2008 at 04:07PM PDT, ID: 21578653

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.15.2008 at 04:42PM PDT, ID: 21578835

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.22.2008 at 10:50PM PDT, ID: 21629620

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.27.2008 at 07:58AM PDT, ID: 21652381

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
05.28.2008 at 12:00AM PDT, ID: 21658265

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
06.16.2008 at 08:55AM PDT, ID: 21794823

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • Automotive
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Displays / Monitors
  • Handhelds / PDAs
  • Components
  • Peripherals
  • Laptops/Notebooks
  • Servers
  • Misc
  • Apple
  • Embedded Hardware
  • Networking Hardware
  • Storage
  • Desktops
  • New Users
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMware
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Virtualization
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • Web Computing
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Consulting
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMware
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Automation
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Web Services
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Web Computing
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Lounge
  • Business Travel
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
  • Automotive
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
05.14.2008 at 11:25PM PDT, ID: 21571020

Rank: Genius

Have you tried using:
Workbooks.Open Filename:=fileToOpen, UpdateLinks:=False, ReadOnly:=True

http://msdn.microsoft.com/en-us/library/aa195811(office.11).aspx

Regards,

Rob.
 
05.15.2008 at 08:00AM PDT, ID: 21574371
Why would I set update links to false?  The whole purpose is to have the raw material costs in one workbook and not in each of the 5 quoting workbooks.
 
05.15.2008 at 02:20PM PDT, ID: 21578078

Rank: Genius

Oh, personal preference.....sorry, I normally use false to that was automatic. In your case, just set that to true.

Workbooks.Open Filename:=fileToOpen, UpdateLinks:=True, ReadOnly:=True

Rob.
 
05.15.2008 at 03:06PM PDT, ID: 21578361
When opening up a second quote workook ist still throws up the do you want to reopen dialog and and debug mode / runtime error [Method 'Open' of object 'Workbooks' failed] when materials.xls is not reopened.
 
05.15.2008 at 03:13PM PDT, ID: 21578397
To clarify, the last comment is related to Problem b in the question.  Problem a & c are still there because the function still has issues.
 
05.15.2008 at 04:07PM PDT, ID: 21578653

Rank: Genius

OK, try this

Application.DisplayAlerts = False
Workbooks.Open Filename:=fileToOpen, UpdateLinks:=True, ReadOnly:=True
Application.DisaplayAlerts = True

That should force a "yes" answer to the "re-open" dialog.

Regards,

Rob.
 
05.15.2008 at 04:42PM PDT, ID: 21578835
Worse problems.  Now any temporary changes that were made in materials.xls are lost because it automaticly reopens materials.xls.  The VBA runtime error dialog still comes up.

I still believe I need to have some error / dialog handling done within a function call.  It's just that the existing function misses some of the scenerios.

Thanks for the help so far.  Will be out until Tuesday for medical testing.  Will start back on this then.

Bob
 
05.22.2008 at 10:50PM PDT, ID: 21629620

Rank: Genius

I'm sorry....I'm having a lot of trouble understanding how you want it to operate.  I don't understand the part about changing values in Materials.xls when it is set to read-only anyway....that's seems a bit odd...

Maybe we can break it down a little bit....why have you done you're own checking about whether Materials.xls is open?  Is that just so you don't prompt the user the file is already open?

Regards,

Rob.
 
05.27.2008 at 07:58AM PDT, ID: 21652381
Hi Rob:

Thanks for getting back.

Why the checking?  Suppressing the read only alert is highly desirable and eliminating the VBA debug error is needed.  The main reason is to prevent the user from having the option to reopen Materials.xls during a quote session & lose any changes.  This has happened in the past due to carelessness and cost us a couple of orders.

As to changing values in the read only Materials.xls - the vast majority of items do not change unless our distributors do a price change.  Some raw material is sold to us on a quote per order since these are commodity type materials [Oak, Maple, etc.].  There are cells in Materials.xls to enter these values.  And a couple of items are discounted if ordered in larger than normal lots.  If the user is doing more than a quick quote, they saveas the quote workbooks & materials in a new folder.

Bob
 
05.28.2008 at 12:00AM PDT, ID: 21658265

Rank: Genius

Hi, using the code below allows the user, without error, to control whether they want to re-open the Materials.xls workbook or not, but I'm guessing that you want to *force* the user to not re-open the workbook, so I'll have to do more testing.....

Regards,

Rob.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
Private Sub Workbook_Open()
    Application.WindowState = xlMaximized
    Dim wb As Workbook
    Set wb = ThisWorkbook
    Dim openPath As String
    Dim fileToOpen As String
    openPath = ThisWorkbook.Path
    fileToOpen = openPath & "\Materials.xls"
    On Error Resume Next
    Workbooks.Open Filename:=fileToOpen, UpdateLinks:=False, ReadOnly:=True
    If Err.Number = 0 Then
        MsgBox "Workbook re-opened."
    Else
        MsgBox "Workbook was not re-opened."
    End If
    wb.Worksheets("Start").Activate
End Sub
 
Function IsFileOpen(strFullPathFileName As String) As Boolean
  Dim hdlFile As Long
  '// Error is generated if you try
  '// opening a File for ReadWrite lock >> MUST BE OPEN!
  On Error GoTo FileIsOpen:
    hdlFile = FreeFile
    Open strFullPathFileName For Random Access Read Write Lock Read Write As hdlFile
    IsFileOpen = False
    Close hdlFile
    Exit Function
FileIsOpen:
    '// Someone has it open!
    IsFileOpen = True
    Close hdlFile
End Function
Open in New Window
Accepted Solution
 
06.16.2008 at 08:55AM PDT, ID: 21794823
Thanks for the help Rob.  We had some emergencies come up and this project was put on hold.  Im going to open up a new question now that I have time to get back to this issue.

Bob
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628