opret textbox via vba i dialogbox
Så er det mig der mangler lidt hjælp!!Jeg vil gerne opret en textbox eller input box i en dialogbox, men kan ikke få det til at virke. Jeg kan ikke redigere i den textbox jeg opretter. Så jeg er kørt lidt fast
Jeg er hellere ikke klar over om en textbox er det korrekt at bruge??
koden ser således (søg efter problem)
Sub Printtotal()
Dim i As Integer
Dim TopPos As Integer
Dim SheetCount As Integer
Dim PrintDlg As DialogSheet
Dim CurrentSheet As Worksheet
Dim OriginalSheet As Worksheet
Dim cb As CheckBox
Const Visudskrift As Boolean = False 'true i test mode
Application.ScreenUpdating = False
' Check for protected workbook
If ActiveWorkbook.ProtectStructure Then
MsgBox "Workbook is protected.", vbCritical
Exit Sub
End If
' Add a temporary dialog sheet
Set OriginalSheet = 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
' PrintDlg.CheckBoxes(SheetCount).Check = True
TopPos = TopPos + 13
End If
Next i
If SheetCount > 0 Then ' sæt en all tjekboks
SheetCount = SheetCount + 1
PrintDlg.CheckBoxes.Add 78, TopPos, 150, 16.5
PrintDlg.CheckBoxes(SheetCount).Text = "All"
TopPos = TopPos + 13
End If
PrintDlg.TextBoxes.Add 82, TopPos + 5, 100, 12 '"""" problemmet er her""""
PrintDlg.TextBoxes(1).Text = "A1:I20" 'default område
PrintDlg.TextBoxes(1).LockedText = False
TopPos = TopPos + 15
' 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
OriginalSheet.Activate
Application.ScreenUpdating = True
If SheetCount <> 0 Then
If PrintDlg.Show Then
If PrintDlg.CheckBoxes(SheetCount).Value = xlOff Then ' all valgt
For Each cb In PrintDlg.CheckBoxes
If cb.Value = xlOn Then ' markere ark der er "hakket"
Worksheets(cb.Caption).Select Replace:=False
End If
Next cb
Else
For Each ws In Worksheets ' markere alle ark
ws.Select Replace:=False
Next ws
End If
PrintDlg.TextBoxes(1).Text = ""
If PrintDlg.TextBoxes(1).Text = "" Then ' område indtatset
'ActiveWindow.SelectedSheets.PrintPreview
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Preview:=Visudskrift, Collate:=True
Else
Range(PrintDlg.TextBoxes(1).Text).Select ' markere område
ActiveWindow.Selection.PrintOut Copies:=1, Preview:=Visudskrift, Collate:=True
End If
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
OriginalSheet.Activate
End Sub
