+ Reply to Thread
Results 1 to 4 of 4

Advise: Opening & closing of data files multiple times in macros related to a process

  1. #1
    Forum Contributor
    Join Date
    08-20-2019
    Location
    Mumbai
    MS-Off Ver
    Office 365
    Posts
    101

    Advise: Opening & closing of data files multiple times in macros related to a process

    Hi,

    I need your advise on the below.

    I have multiple macros running which uses 4 workbooks.
    1. Book1 - This has all the buttons, forms and macros
    2. Book2 - 4: These are Data files - e.g. Customer Master, Product Master, Transactions Data

    Book1 has various Buttons e.g. Add New Customer, Update/Delete Customer, Add New Product, Update/Delete Product, Add a Transaction, etc.

    Every time a button is clicked one or more user forms are opened and macros are executed. For each button operation one or more data files are opened, the necessary changes are performed and the files are closed before the operation of that button ends.

    The objective in doing so is to not allow the user to get access to the data files. However, in this process the data files get opened and closed every time a button is clicked.

    Is this optimal way to write the macros?
    Is there any better way to handle this process?

    rgds
    hemant

  2. #2
    Valued Forum Contributor PaulSP8's Avatar
    Join Date
    11-21-2017
    Location
    Chorley, England
    MS-Off Ver
    2013 & 2021
    Posts
    437

    Re: Advise: Opening & closing of data files multiple times in macros related to a process

    If you switch off Screen Updating then the users shouldn't see any of the workbooks that open in the background.

    Please Login or Register  to view this content.
    At the start of your code.

    Please Login or Register  to view this content.
    At the end.

    Other than that then if you post your code (or even better, an example workbook) then we might be able to help more.

  3. #3
    Forum Contributor
    Join Date
    08-20-2019
    Location
    Mumbai
    MS-Off Ver
    Office 365
    Posts
    101

    Re: Advise: Opening & closing of data files multiple times in macros related to a process

    Thanks Paul.

    I am aware of the ScreenUpdating option. I have used it.

    Let me explain with the help of the attached image.
    Attachment 641975

    When the user opens my process file (book1) the buttons as per attached image will be seen. For every button click a user form will pop-up, the required data file(s) will be opened in the background, the user will perform the necessary operation, the data will be written in the data files and the files will get closed. This happens for every button click till the user form is open.

    One option is to open the data files with the file open event of Book1 and close the data files when the Book1 is closed. However, that will leave the data files open and the user will be able to access them. Therefore I am opening and closing the data files for every button operation.

    I wanted to know
    Is there any way to write in the data files without opening?
    OR
    Is there any other way to handle this so that repeated opening and closing of data files are avoided.

    regards
    hemant

  4. #4
    Valued Forum Contributor PaulSP8's Avatar
    Join Date
    11-21-2017
    Location
    Chorley, England
    MS-Off Ver
    2013 & 2021
    Posts
    437

    Re: Advise: Opening & closing of data files multiple times in macros related to a process

    I've never needed to Read / Write from a closed Workbook myself so not sure, I took a quick look on Google and it does seem that it can be done but it's not something that is straight forward - Seemed to be a few different ways of doing it so I'll let you take a look at the different methods available instead of trying to link or list them here

    That said, from what I understand of what is happening...

    1) Click Button
    2) Second Workbook Opens with information (or however many the information is stored across, for simplicity I'll just have one open for now ;-) )
    3) User Makes a Change on Userform based on details from second Workbook.
    4) Second Workbook is updated, saved and closed.

    But you're concerned that during step 3 that the user has access to the data in the second workbook?

    If that's the case then you could...

    1) Click Button
    2) Second Workbook Opens with information
    3) Load all relevant details in to Variables
    4) Close second workbook
    5) User Makes a Change on Userform based on details from Variables
    6) Reopen Second Workbook
    7) Make changes from the stored variables
    8) Close and save second workbook.

    Personally I'd be tempted to start looking at Access for something like this - Either as means of storing all the information in Linked tables and building Queries or, just handling it all through Forms from within Access.

    Sorry I can't be of more help - Maybe someone else can pick this up from the bump though

+ 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. Iterative process to import multiple text files into multiple excel files
    By Ecth3lion in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-29-2018, 01:04 PM
  2. Want to automate a daily process and need some advise and insight
    By dwhite30518 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-11-2013, 10:49 PM
  3. Replies: 2
    Last Post: 03-04-2012, 11:58 AM
  4. Replies: 6
    Last Post: 02-15-2012, 07:52 AM
  5. Odd behaviour with opening and closing xls files with macros
    By hippie_dream in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-11-2011, 10:24 PM
  6. [SOLVED] Re: Opening and closing files in a Macro
    By Henry Stock in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-18-2005, 03:00 PM

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