Open a Workbook in the Background

Solved
zapp56 Posted messages 26 Registration date   Status Membre Last intervention   -  
 zapp56 -
Hello everyone,

I am currently developing an Excel VBA application that utilizes several databases.

I have searched for a solution to this problem but without success, as the description leads me to "how to hide a workbook."

I have a userform as an interface whose code checks if the database is already open before opening it for use.
If it is closed at the beginning, then it will close it afterwards, so far so good.

If it is open at the beginning, I would like it to remain open at the end, but in the background.
However, after processing the data, the database stays in the foreground and hides the userform.
I have tried using Activate on my first workbook but it makes no difference. xlMinimize is not an option; I just want to bring the main workbook to the foreground with the userform.

Any ideas, please?

Thank you in advance.

5 réponses

zapp56
 
Hello,

@yg_be I hope you understand that the data I’m working with is sensitive and very confidential, which is why I can't share my code; I would have needed to create new code in order to publish it.

To everyone, I just realized that my problem is a misunderstanding of the windowstate xlminimized method.
Indeed, I thought this method affected the size of the window rather than its state.

So xlminimized is indeed the solution to my problem.

I apologize for the time I made you lose, but I also want to thank you for your willingness to help me. I wish you all the best, and I'm truly sorry.
1
yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   Ambassadeur 1 588
 
Hello,
what software do you use for your databases?
In which workbook can I find the VBA code?
Show us the code you tried (Activate on my 1st Workbook). Use code tags when sharing code: https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
0
zapp56 Posted messages 26 Registration date   Status Membre Last intervention   1
 
Hello, and thank you for your interest.

I'm on my phone, so I can't send my code (or not until next week since it's a work file).

My databases are simple Excel sheets (xlsx) that I call with Workbooks.Open, and my entire application is in a userform of my workbook (xlsm).

The problem is that the xlsx files open, but if I don't close them, they stay in front, and I have to manually select the xlsm workbook to return to my userform.

I've tried workbooks("file.xlsm").activate, but I feel like the userform is blocking the foreground switch.
0
yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   1 588
 
I don't have anything similar that allows me to test.
Maybe by doing
show
of the userform?
0
zapp56 Posted messages 26 Registration date   Status Membre Last intervention   1
 
Hello,

And I'm sorry if it took me a while to get back to you, I've been very busy for family reasons.
To put it concisely:

I use 2 workbooks:
"Macro.xlsm" which contains my code (userform).
"BDD.xlsx" which contains my database.

The code is intentionally set to open the BDD as read-only.
When the code is about to open the BDD, it checks if the file is already open. (I get a true/false return)

Case 1: The BDD was not open (false). It opens it, copies the data to the first workbook, then closes the BDD. (no issues there)

Case 2: The BDD is already open (true). It selects it, copies the data to the first workbook, and keeps the BDD open (no issues there)

Problem: In Case 2, the BDD is in the foreground, in front of my userform, and I have to click on the "minimize" bar to continue using the first workbook and the userform.

I've tried:
> Workbooks("Macro.xlsm").Activate
But it doesn't work because I think it can't activate workbook 1 since the userform is open.
Note: I would prefer to continue using this userform modal, and not use the formula "xlMinimize".

That's all, thank you for your help, if you can.
0
yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   1 588
 
you still don't show any code.

if you share your files, I could test. I'm wondering if sometimes you need to complement an activate with a select.

"click on the "minimize" bar": what is it about? have you tried to "minimize" via VBA?

"it cannot activate workbook 1 since the userform is open": maybe close the userform via VBA?

"xlMinimize is not an option": doesn't it work?
0
f894009 Posted messages 17417 Registration date   Status Membre Last intervention   1 717
 
Hello everyone,

zapp56
I had you on follow-up and haven't heard anything, but never mind.

Why do you want your BDD sheet to be in the foreground in read-only mode at the start, what's the purpose?
0