Put DialogBox in Center of Window

alyssa75

Board Regular
Joined
May 14, 2007
Messages
240
I am creating a dialogbox as follows:

Set PrintDlg = ActiveWorkbook.DialogSheets.Add


I want teh box to appear in the center (or close to it) of the window instead of up in the corner.

Any ideas?

Thanks!
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Try like this

Code:
Sub test()
Dim PrintDlg As Object
Set PrintDlg = ActiveWorkbook.DialogSheets.Add
ActiveSheet.Shapes("Dialog 1").Select
Selection.ShapeRange.IncrementLeft 250
Selection.ShapeRange.IncrementTop 150
ActiveSheet.Shapes("Button 2").Select
Selection.ShapeRange.IncrementLeft 250
Selection.ShapeRange.IncrementTop 150
ActiveSheet.Shapes("Button 3").Select
Selection.ShapeRange.IncrementLeft 250
Selection.ShapeRange.IncrementTop 150
End Sub
 
Upvote 0
This was suggested to me when I inquired about putting checkboxes next to a list to select sheets to print...

here is the code I am using: - I'd love to see what your suggestion looks like. I actually am struggling with this as I want the descriptions next to the checkboxes to be something other than the tab names, since those are semi-cryptic. I had intended to store the description for each box in cell b2, but could not figure out how to modify this to know what the tab name is then. (it looks at the caption and so when I started pulling b2 it broke since it was looking for a tab named that way)

Sub PrintSelectSheets()
Dim i As Integer
Dim TopPos As Integer
Dim SheetCount As Integer
Dim PrintDlg As DialogSheet
Dim StartingSheet As Worksheet
Dim CurrentSheet As Worksheet
Dim cb As CheckBox

DefaultGroupingsAll
Dim NumCopies As String
NumCopies = InputBox(Prompt:="How many copies would you like to print?", Title:="Number of Printed Copies")


application.ScreenUpdating = False

'** Add a temporary dialog sheet
Set StartingSheet = ActiveSheet
Set PrintDlg = ActiveWorkbook.DialogSheets.Add

SheetCount = 0

'** Add the checkboxes
TopPos = 40
For i = 1 To ActiveWorkbook.Worksheets.Count
Set CurrentSheet = ActiveWorkbook.Worksheets(i)

'Skip empty sheets and hidden sheets
If application.CountA(CurrentSheet.Cells) <> 0 And _
CurrentSheet.Visible Then
SheetCount = SheetCount + 1
PrintDlg.CheckBoxes.Add 78, TopPos, 150, 16.5
PrintDlg.CheckBoxes(SheetCount).Text = _
CurrentSheet.Name
TopPos = TopPos + 13
End If
Next i

'Move the OK and Cancel buttons
PrintDlg.Buttons.Left = 240

'Set dialog height, width, and caption
With PrintDlg.DialogFrame
.Height = application.Max _
(68, PrintDlg.DialogFrame.Top + TopPos - 34)
.Width = 230
.Caption = "Select Sheets to Print"
End With

'Change tab order of OK and Cancel buttons
'so the 1st option button will have the focus
PrintDlg.Buttons("Button 2").BringToFront
PrintDlg.Buttons("Button 3").BringToFront

' Display the dialog box
StartingSheet.Activate
application.ScreenUpdating = True
If SheetCount <> 0 Then
If PrintDlg.Show Then
For Each cb In PrintDlg.CheckBoxes
If cb.Value = xlOn Then
Worksheets(cb.Caption).Activate
ActiveWindow.SelectedSheets.PrintOut Copies:=NumCopies
End If

Next cb
End If
Else
MsgBox "All worksheets are empty."
End If

' Delete temporary dialog sheet (without a warning)
application.DisplayAlerts = False
PrintDlg.Delete

'Reactivate original sheet
StartingSheet.Activate
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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