+ Reply to Thread
Results 1 to 4 of 4

Writing to another workbook

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Falmouth, VA now, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    615

    Writing to another workbook

    Periodically when a cell is updated I need whichever of the 10 to 20 satellite workbooks to post three cells to the receptionist's workbook.

    The receptionist's workbook is normally open, but if it is not, I have included code to test and open it.

    Because we are only posting three cells I expect the action to be very fast (I hope).

    The receptionist never will alter any cell in the receptionist workbook, only view.

    Receptionist normally will have receptionist workbook open when a satellite workbook must activate it and write to it.

    Because of the relative lack of frequency, the chances of more than one satellite workbook needing to access and write to the receptionist workbook are remote, but it is possible (Over the course of a full day, perhaps a total of 200 writes to the receptionist notebook are expected).

    What problems can I anticipate and program to avoid (and how if you can!)?

  2. #2
    Registered User
    Join Date
    04-04-2013
    Location
    Prague
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Writing to another workbook

    Hi,
    If I understand right, the receptionist do not need read/write access. Lock files for editing by password and let the macro code to access receptionist file anytime. I think it should work. Unfortunately I cannot try it, have just one PC.


    cheers,

    Tomas

  3. #3
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Writing to another workbook

    I also only have a single user system. I think Bruce's concern is not from the receptionist, but from a possible race condition when two satellites attempt to update the receptionist simultaneously.

    One way to possibly reduce collisions (it might make things worse) is for the satellites to attempt to open and lock another Excel file prior to accessing the receptionist Excel file. The other Excel file would just serve as a locking mechanism.

    Pseudo Code
    While NOT able to open and lock file XYZ
      wait 200 milliseconds
    While End
    
    Access and update the Receptionist file
    
    Close file XYZ
    You could test file XYZ with code similar to (actual working and tested code on Vista 32 bit single user system using Excel 2003):
    Function IsFileOpen(sPathAndFileName As String)
      'This determines whether a file is open
      
      Dim iFileNumber As Integer
      Dim iError As Integer
    
      On Error Resume Next       ' Turn error checking off.
      iFileNumber = FreeFile()   ' Get a free file number.
      
      'Attempt to open the file and lock it.
      Open sPathAndFileName For Input Lock Read As #iFileNumber
      Close iFileNumber          ' Close the file.
      iError = Err               ' Save the error number that occurred.
      On Error GoTo 0            ' Turn error checking back on.
    
      ' Check to see which error occurred.
      Select Case iError
    
        ' No error occurred.
        ' File is NOT already open by another user.
        Case 0
          IsFileOpen = False
    
        ' Error number for "Permission Denied."
        ' File is already opened by another user.
        Case 70
          IsFileOpen = True
    
        ' Another error occurred.
        Case Else
            Error iError
            
      End Select
    
    End Function
    Lewis

  4. #4
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Falmouth, VA now, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    615

    Re: Writing to another workbook

    Thank-you.

    I will experiment and report progress.

    Seems strange that this kind of thing has not been done by others, but then it seemed strange all the trouble I ran into trying to work with linking in the same basic model...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. HELP! Writing to Master Workbook.
    By Magoci in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-04-2012, 12:49 AM
  2. writing an If function linking to another workbook
    By denvernuggets15 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-19-2012, 03:46 AM
  3. Restrict user from over-writing workbook
    By TwoyTaylor in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-24-2008, 11:23 PM
  4. [SOLVED] Reading Writing Data from One WorkBook to Another
    By John Pierce in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-30-2005, 05:05 PM
  5. writing data to a new workbook?
    By marsupilami in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-11-2005, 03:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1