I'm looking for a Macro to Close File B and File C (without saving them) through File A
problem description:
I have a File A that serves as a master pilot, that is, through this file A, I execute many operations, and I want to close File B and File C with Macro (without saving them)
Note:
- File A the master pilot is open
- File B and File C that need to be closed by the macro are also open
hugs
[Solved] Close File B and File C through File A
[Solved] Close File B and File C through File A
Last edited by Math on Tue Nov 20, 2018 8:22 pm, edited 1 time in total.
LibreOffice 5.4.4.2 on Windows 7
Re: Close File B and File C through File A
How is this different from the previous answer Close multiple files?
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: Close File B and File C through File A
model 1: If Close the files already soon after Opening the files, then the previous response is very good , example :
REM macro1
Sub Open Close Files
Open File 1
Open File 2
..............
Open File N
Close File 1
Close File 2
.................
Close File N
End Sub
model 2: If you run Another Macro after Opening the files, and only later Close the files, then the previous answer DOES NOT solve, example :
REM macro1
Sub Open Files
Open File 1
Open File 2
..............
Open File N
End Sub
REM macro2
Sub Other Macro
...............
...............
End Sub
REM macro3
Sub Close Files
Close File 1
Close File 2
................
Close File N
End Sub
Comments:
there are situations that I execute the model 1 and situations that I execute the model 2
to run model 2 you need to close the files differently than model 1, so the previous answer does not solve
Thank you for your attention
REM macro1
Sub Open Close Files
Open File 1
Open File 2
..............
Open File N
Close File 1
Close File 2
.................
Close File N
End Sub
model 2: If you run Another Macro after Opening the files, and only later Close the files, then the previous answer DOES NOT solve, example :
REM macro1
Sub Open Files
Open File 1
Open File 2
..............
Open File N
End Sub
REM macro2
Sub Other Macro
...............
...............
End Sub
REM macro3
Sub Close Files
Close File 1
Close File 2
................
Close File N
End Sub
Comments:
there are situations that I execute the model 1 and situations that I execute the model 2
to run model 2 you need to close the files differently than model 1, so the previous answer does not solve
Thank you for your attention
LibreOffice 5.4.4.2 on Windows 7
Re: Close File B and File C through File A
I am puzzled by your code structure in Model 2. If the files are not used in Sub Other Macro or Sub Close Files, then you can close them in Sub Open Files. If the files are used in the other subs, then you have variables available to close them.
In any case, you can assign the files to a Global, Public or Private variable that can be accessed from any sub. Note that the variable is declared outside of any sub. From the Help:
Scope of Variables
A variable defined within a SUB or FUNCTION, only remains valid until the procedure is exited. This is known as a "local" variable. In many cases, you need a variable to be valid in all procedures, in every module of all libraries, or after a SUB or FUNCTION is exited.
Declaring Variables Outside a SUB or FUNCTION
GLOBAL VarName As TYPENAME
The variable is valid as long as the OpenOffice session lasts.
PUBLIC VarName As TYPENAME
The variable is valid in all modules.
PRIVATE VarName As TYPENAME
The variable is only valid in this module.
DIM VarName As TYPENAME
The variable is only valid in this module.
In any case, you can assign the files to a Global, Public or Private variable that can be accessed from any sub. Note that the variable is declared outside of any sub. From the Help:
Scope of Variables
A variable defined within a SUB or FUNCTION, only remains valid until the procedure is exited. This is known as a "local" variable. In many cases, you need a variable to be valid in all procedures, in every module of all libraries, or after a SUB or FUNCTION is exited.
Declaring Variables Outside a SUB or FUNCTION
GLOBAL VarName As TYPENAME
The variable is valid as long as the OpenOffice session lasts.
PUBLIC VarName As TYPENAME
The variable is valid in all modules.
PRIVATE VarName As TYPENAME
The variable is only valid in this module.
DIM VarName As TYPENAME
The variable is only valid in this module.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: Close File B and File C through File A
[Solved]
Many thanks for your help, mr. FJCC
hugs
Many thanks for your help, mr. FJCC
hugs
LibreOffice 5.4.4.2 on Windows 7