Workbook_Open - how to combine one and more codes?

rediffusion

Board Regular
Joined
Apr 24, 2019
Messages
60
Hi all! I duplicate this question because сouldn't find a solution. :( Cross-post is here. :warning:

I have in <code style="margin: 0px; padding: 1px 5px; border: 0px; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; background-color: rgb(239, 240, 241); white-space: pre-wrap; color: rgb(36, 39, 41);">PERSONAL.XLSB</code> some code. This <code style="margin: 0px; padding: 1px 5px; border: 0px; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; background-color: rgb(239, 240, 241); white-space: pre-wrap; color: rgb(36, 39, 41);">VBA</code> Saves and closes all books after clicking on the red cross. It works without any problems:

<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">PrivateWithEvents xlApp As Application

PrivateSub Workbook_Open()
Set xlApp = Application
EndSub

<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">PrivateSub xlApp_WorkbookBeforeClose(ByVal Wb As Workbook, Cancel AsBoolean)
xlApp
.ScreenUpdating =False
xlApp
.DisplayAlerts =False
xlApp
.EnableEvents =False
ForEach Wb In xlApp.Workbooks
Wb
.Save 'Wb.Close True
Next
xlApp
.Quit
EndSub

I have another code which I want to work, when I open the Excel. Separately, this code works, but I do not know how to combine? This code opens my own tab on Ribbon:

<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">PrivateSub Workbook_Open()
SendKeys
"%BP{F6}",True
EndSub

Want to work when I open any Workbook.
:help:</code></code></code>
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Code:
Private WithEvents xlApp As Application

PrivateSub Workbook_Open()
  Set xlApp = Application
  SendKeys "%BP{F6}", True
EndSub
 
Upvote 0

<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Private WithEvents xlApp As Application

Private Sub Workbook_Open()
Set xlApp = Application
End Sub

<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Private Sub xlApp_WorkbookBeforeClose(ByVal Wb As Workbook, Cancel AsBoolean)
xlApp
.ScreenUpdating =False
xlApp
.DisplayAlerts =False
xlApp
.EnableEvents =False
ForEach Wb In xlApp.Workbooks
Wb
.Save 'Wb.Close True
Next
xlApp
.Quit
End Sub

I have another code which I want to work, when I open the Excel. Separately, this code works, but I do not know how to combine? This code opens my own tab on Ribbon:

<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Private Sub Workbook_Open()
SendKeys
"%BP{F6}",True
End Sub</code></code></code>

I made mistakes in the code. Corrected the gaps in codes!
 
Last edited:
Upvote 0
@shg

Finally i solve this issue.

So if we have the codes then just shove inside and that's it:
Code:
[COLOR=#000000][FONT=monospace]Workbook_Open()[/FONT][/COLOR]

As for this line the problem was in the version of Office:
Code:
[COLOR=#000000][FONT=monospace]SendKeys [/FONT][/COLOR][COLOR=maroon][FONT=monospace]"%БП{F6}"[/FONT][/COLOR]
In "Microsoft Office 365 2019" everything works well!

Sorry for the stupid Topic!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top