+ Reply to Thread
Results 1 to 9 of 9

Automating accepting "OK" from msgbox in another file

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-02-2013
    Location
    Harrisburg, PA
    MS-Off Ver
    Office 365 MSO (16.0.10730.20264) 32-bit
    Posts
    160

    Automating accepting "OK" from msgbox in another file

    Hi All. I am doing some automation for users of an IT dept created file. The IT file is a protected workbook with protected modules.

    Current process: The user opens the IT xlsm file, copies / Pastes by value the updated data (from USER file) and then saves the IT file (located on a sharepoint). The IT file also has a macro button to "Upload" the new raw data to a server. So, 2 things are done, the IT file is updated and saved, and Data is push to a server. Regardless if you hit the macro button to upload the data to the server or not, the IT Workbook_BeforeSave has a MsgBox("Do you want to upload data", vbYesNo, strTitle), you need to click yes or no.

    I am automating this from the USER file. From a macro button in the USER file, I
    1) open the IT (sharepoint) file
    2) auto copy paste special data from USER to IT
    3) save IT file
    4) I still need to upload the data in the file to their server....

    So I can either do a or b...
    a) On Save, the IT file Workbook_BeforeSave runs asking if you want to upload data Yes / No. How can I accept the "yes" with code from the USER file...
    or
    b) run IT upload macro "Public Sub btnUpload_Click()" from USER and bypass the BeforeSave Msgbox


    Thanks
    Steve
    Last edited by Steveapa; 11-18-2023 at 12:51 PM. Reason: Solved

  2. #2
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,055

    Re: Automating accepting "OK" from msgbox in another file

    Code execution is paused when a msgbox is shown so I don't think you can click it programmatically.
    You probably need some flag or variable in the IT file which you can set from the user file, or maybe something in the IT file that detects that the active workbook is the user fileto skip the msgbox altogether

  3. #3
    Forum Contributor
    Join Date
    10-02-2013
    Location
    Harrisburg, PA
    MS-Off Ver
    Office 365 MSO (16.0.10730.20264) 32-bit
    Posts
    160

    Re: Automating accepting "OK" from msgbox in another file

    Hey... Thanks for the Reply. Yes, the solution is in the IT file. But as an engineer / user / self taught for 30yrs... upgrading their solution to make it easier for the users, our IT dept does not like me and won't change their stuff. I could automate moving the mouse to the OK location click the mouse!

  4. #4
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,055

    Re: Automating accepting "OK" from msgbox in another file

    I could automate moving the mouse to the OK location click the mouse!
    I don't think that is possible using Excel. Once the msgbox is displayed no code will run until it's dismissed.

    You can't modify the IT file, but as it produces the msgbox, that's where changes would need to be made.

    Obviously I don't know any detail, but generally I'd be hesitant to perform an upload in the BeforeSave event as it's vulnerable to data loss if something went wrong.

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,789

    Re: Automating accepting "OK" from msgbox in another file

    I have a concept but I have no idea how to implement this in VBA, or if it's possible. The idea would be to open the IT file without enabling macros. I have never done that in VBA but it's an avenue you might be able to pursue.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  6. #6
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,055

    Re: Automating accepting "OK" from msgbox in another file

    Could try moving it to an untrusted location and adding data to it there before moving it back. I'm unsure if opening a file in an untrusted location with code would enable the macros in it though.

    You'd then open the file again after being moved back to run the upload code and close without saving.

    Something like this
    1. check that the proper IT file isn't read only. Abort if it is.
    2. copy it to an untrusted location
    3. set the readonly, property of the real file to true,so if someone else tries the same it will abort.
    4. open copy, add data,save and close.
    5. replace the proper copy with the updated one
    6. open it, run upload,close without saving
    Last edited by ByteMarks; 11-18-2023 at 06:04 AM.

  7. #7
    Forum Contributor
    Join Date
    10-02-2013
    Location
    Harrisburg, PA
    MS-Off Ver
    Office 365 MSO (16.0.10730.20264) 32-bit
    Posts
    160

    Re: Automating accepting "OK" from msgbox in another file

    Thanks ByteMarks... You got me thinking.
    Here is the solution... I disable events before opening the IT workbook - this stops workbook open from running. I run the macro in the IT file I want to run, I close and save without running the IT beforesave macro!
    Application.EnableEvents = False
    Set tep_pl_wb = Workbooks.Open(sharepoint_path)
    Application.Run "'P&L.xlsm'!btnUpload_Click"
    tep_pl_wb.Close (True)
    Application.EnableEvents = True
    Last edited by Steveapa; 11-18-2023 at 01:08 PM. Reason: send tanks

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,789

    Re: Automating accepting "OK" from msgbox in another file

    Oh, that's a good idea. I had forgotten that disabling events is global to the entire Excel instance, and not specific to the workbook where the code to disable events is run.

  9. #9
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,055

    Re: Automating accepting "OK" from msgbox in another file

    Great solution.

+ 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. [SOLVED] automatically accepting "protected View"
    By peterschein in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-17-2019, 03:17 AM
  2. [SOLVED] msgbox: Show "Hi" when i open excel file based on cell value
    By ganeshkumar in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-17-2017, 11:17 AM
  3. If msgBox "File is locked for editing appears" then click cancel and end macro
    By biancam3392 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-20-2015, 03:25 AM
  4. Replies: 9
    Last Post: 10-31-2014, 10:54 AM
  5. [SOLVED] If Not ActiveSheet.Range("A1").Value Like "apple" Then MsgBox "Error"
    By HerryMarkowitz in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-18-2014, 02:16 PM
  6. Transfert cell values from file "A" to file "B" skipping columns in file "B".
    By Sentrosi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-16-2009, 11:11 PM
  7. [SOLVED] Msgbox saying "Unable to read file"
    By lashio in forum Excel General
    Replies: 3
    Last Post: 05-30-2005, 03:05 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