Userform Opening in Wrong Window

jta

New Member
Joined
Oct 19, 2022
Messages
1
Office Version
  1. 2019
Platform
  1. Windows
My userform is opening in the wrong window but only if I call a certain sub in my main sub.

On userform
VBA Code:
Private Sub UserForm_Initialize()
'PURPOSE: Position userform to center of Excel Window (important for dual monitor compatibility)
'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault

'Start Userform Centered inside Excel Screen (for dual monitors)
  Me.StartUpPosition = 0
  Me.Left = Application.Left + (0.5 * Application.Width) - (0.5 * Me.Width)
  Me.Top = Application.Top + (0.5 * Application.Height) - (0.5 * Me.Height)

End Sub

Main sub
VBA Code:
Sub Python_Run2()
Application.Run "iInstallAddin" ' if I remvove this call the userform opens centered
Dim passwd, pye, pys As String
Dim windowStyle As Integer
Dim waitOnReturn As Boolean
Dim objShell As Object
Run ("Python_Cfg.xlam!Python_Cfg")
passwd = Workbooks("Python_Cfg.xlam").pass
pye = Workbooks("Python_Cfg.xlam").PythonExe
windowStyle = Workbooks("Python_Cfg.xlam").windowStyle
waitOnReturn = Workbooks("Python_Cfg.xlam").waitOnReturn
Set objShell = Workbooks("Python_Cfg.xlam").objShell
pys = "H:\jadamec\Python\vba_test.py"

objShell.Run pye & " " & pys & " " & passwd, windowStyle, waitOnReturn


End Sub

iInstallAddin

VBA Code:
Sub iInstallAddin()

On Error Resume Next
AddIns("Python_Cfg").Installed = False
AddIns.Add fileName:="G:\Production\shared\Excel\VBA\vba\Python_Cfg.xlam", copyfile:=False
AddIns("Python_Cfg").Installed = True
End Sub


Any ideas?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Try moving the centering code

VBA Code:
'Start Userform Centered inside Excel Screen (for dual monitors)
  Me.StartUpPosition = 0
  Me.Left = Application.Left + (0.5 * Application.Width) - (0.5 * Me.Width)
  Me.Top = Application.Top + (0.5 * Application.Height) - (0.5 * Me.Height)

From the Form Intialize event to the Form Activate event
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
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