add a date picker to my text box - excel

ive looked through other posts and I can't quite figure out the day picker for my user form. Any ideas or help would be appreciated. The input date box is currently just a text box to write in the date in the format dd-mmm-yy. As ive been testing the form it's pretty hard to type the date in like this. Since I built the form for someone else I would like it to be a little easier. Thanks
Private Sub UserForm_Initialize()
'Empty TextBox
DateTextBox.Value = ""
CmbBox_ACFT.Value = ""
JCNTextBox.Value = ""
TEMSTextBox.Value = ""
DMGTextBox.Value = ""
MXNTextBox.Value = ""
CmbBox_POS.Clear
CmbBox_Shift.Clear
With CmbBox_Shift
CmbBox_Shift.AddItem "DAYS"
CmbBox_Shift.AddItem "SWINGS"
CmbBox_Shift.AddItem "MIDS"
End With
With CmbBox_POS
CmbBox_POS.AddItem "1"
CmbBox_POS.AddItem "2"
CmbBox_POS.AddItem "APU"
End With
With CmbBox_ACFT
CmbBox_ACFT.AddItem "123"
CmbBox_ACFT.AddItem "456"
CmbBox_ACFT.AddItem "789"
CmbBox_ACFT.AddItem "012"
CmbBox_ACFT.AddItem "782"
End With
Option_Yes.Value = False
DateTextBox.SetFocus
End Sub
Sub OKButton_Click()
Dim emptyRow As Long
'Make Sheet1 active
Sheet1.Activate
'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
'Transfer information
Cells(emptyRow, 1).Value = DateTextBox.Value 'need a date picker to help minimize errors. In dd-mmm-yy format.
Cells(emptyRow, 2).Value = CmbBox_ACFT.Value
Cells(emptyRow, 3).Value = CmbBox_Shift.Value
Cells(emptyRow, 4).Value = CmbBox_POS.Value
Cells(emptyRow, 5).Value = MXNTextBox.Value
Cells(emptyRow, 6).Value = JCNTextBox.Value
Cells(emptyRow, 7).Value = TEMSTextBox.Value
'Cells(emptyRow, 8).Value = DinnerComboBox.Value
Cells(emptyRow, 9).Value = DMGTextBox.Value
If Option_Yes.Value = True Then
Cells(emptyRow, 8).Value = "Yes"
Else
Cells(emptyRow, 8).Value = "No"
End If
With ActiveSheet.UsedRange.Borders
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub

it is entirely possible the date picker control may not be installed. I did find a related post that explains how to ensure it is installed ("Monthview"). You have to install it.
First close Excel.
download MSCOMCT2.cab from http://support.microsoft.com/kb/297381 and extract the two files inside the zip file.
Right click the .inf file and click "Install".
Next, open Windows Explorer and find the directory C:\Windows\System32.
Locate the extracted .ocx file in C:\Windows\System32 and move it to C:\Windows\sysWOW64.
Click Start > Search > "cmd.exe", right-click the found item and click "Run as Administrator"
At the command prompt type "regsvr32 C:\Windows\sysWOW64\MSCOMCT2.ocx" and hit enter
Open Excel and fire up the VB Editor
Click Tools > References and choose "Microsoft Windows Common Controls 2-6.0 (sp6)
Select any userform in the VB project, click Tools > Additional Controls
Select "Microsoft MOnthview Control 6.0 (SP6)
Use 'DatePicker' control in the VBA user form.
From How to Add Date Picker To VBA UserForm

For few versions MSCOMCT2.cab isn't working
You can try out the following script
Option Explicit
Dim ThisDay As Date
Dim ThisYear, ThisMth As Date
Dim CreateCal As Boolean
Dim i As Integer
Private Sub D1_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D1.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D1.ControlTipText
End If
End Sub
Private Sub D10_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D10.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D10.ControlTipText
End If
End Sub
Private Sub D11_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D11.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D11.ControlTipText
End If
End Sub
Private Sub D12_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D12.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D12.ControlTipText
End If
End Sub
Private Sub D13_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D13.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D13.ControlTipText
End If
End Sub
Private Sub D14_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D14.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D14.ControlTipText
End If
End Sub
Private Sub D15_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D15.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D15.ControlTipText
End If
End Sub
Private Sub D16_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D16.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D16.ControlTipText
End If
End Sub
Private Sub D17_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D17.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D17.ControlTipText
End If
End Sub
Private Sub D18_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D18.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D18.ControlTipText
End If
End Sub
Private Sub D19_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D19.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D19.ControlTipText
End If
End Sub
Private Sub D2_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D2.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D2.ControlTipText
End If
End Sub
Private Sub D20_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D20.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D20.ControlTipText
End If
End Sub
Private Sub D21_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D21.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D21.ControlTipText
End If
End Sub
Private Sub D22_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D22.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D22.ControlTipText
End If
End Sub
Private Sub D23_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D23.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D23.ControlTipText
End If
End Sub
Private Sub D24_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D24.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D24.ControlTipText
End If
End Sub
Private Sub D25_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D25.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D25.ControlTipText
End If
End Sub
Private Sub D26_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D26.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D26.ControlTipText
End If
End Sub
Private Sub D27_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D27.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D27.ControlTipText
End If
End Sub
Private Sub D28_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D28.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D28.ControlTipText
End If
End Sub
Private Sub D29_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D29.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D29.ControlTipText
End If
End Sub
Private Sub D3_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D3.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D3.ControlTipText
End If
End Sub
Private Sub D30_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D30.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D30.ControlTipText
End If
End Sub
Private Sub D31_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D31.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D31.ControlTipText
End If
End Sub
Private Sub D32_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D32.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D32.ControlTipText
End If
End Sub
Private Sub D33_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D33.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D33.ControlTipText
End If
End Sub
Private Sub D34_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D34.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D34.ControlTipText
End If
End Sub
Private Sub D35_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D35.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D35.ControlTipText
End If
End Sub
Private Sub D36_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D36.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D36.ControlTipText
End If
End Sub
Private Sub D37_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D37.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D37.ControlTipText
End If
End Sub
Private Sub D38_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D38.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D38.ControlTipText
End If
End Sub
Private Sub D39_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D39.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D39.ControlTipText
End If
End Sub
Private Sub D4_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D4.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D4.ControlTipText
End If
End Sub
Private Sub D40_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D40.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D40.ControlTipText
End If
End Sub
Private Sub D41_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D41.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D41.ControlTipText
End If
End Sub
Private Sub D42_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D42.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D42.ControlTipText
End If
End Sub
Private Sub D5_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D5.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D5.ControlTipText
End If
End Sub
Private Sub D6_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D6.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D6.ControlTipText
End If
End Sub
Private Sub D7_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D7.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D7.ControlTipText
End If
End Sub
Private Sub D8_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D8.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D8.ControlTipText
End If
End Sub
Private Sub D9_Click()
If CBO_AddTime.Value = True Then
Selection.Value = Me.D9.ControlTipText & ":" & Time()
ElseIf CBO_AddTime.Value = False Then
Selection.Value = Me.D9.ControlTipText
End If
End Sub
Private Sub Frame1_Click()
End Sub
Private Sub UserForm_Initialize()
Application.EnableEvents = False
ThisDay = Date
ThisMth = Format(ThisDay, "MM")
ThisYear = Format(ThisDay, "YYYY")
For i = 1 To 12
CB_Month.AddItem Format(DateSerial(Year(Date), Month(Date) + i, 0), "mm")
Next
CB_Month.ListIndex = Format(Date, "mm") - Format(Date, "mm")
For i = -10 To 50
If i = 1 Then CB_Year.AddItem Format((ThisDay), "yyyy") Else CB_Year.AddItem _
Format((DateAdd("yyyy", (i - 1), ThisDay)), "yyyy")
Next
CB_Year.ListIndex = 11
CreateCal = True
Call Build_Calendar
Application.EnableEvents = True
LBLTime.Caption = Time()
LBLDate.Caption = Format(Date)
If CreateCal = True Then
UserForm1.Caption = CB_Month.Value & " " & CB_Year.Value
End If
End Sub
Private Sub Build_Calendar()
For i = 1 To 42
If i < Weekday((CB_Month.Value) & "/1/" & (CB_Year.Value)) Then
Controls("D" & (i)).Caption = Format(DateAdd("d", (i - Weekday((CB_Month.Value) & "/1/" & (CB_Year.Value))), _
((CB_Month.Value) & "/1/" & (CB_Year.Value))), "d")
Controls("D" & (i)).ControlTipText = Format(DateAdd("d", (i - Weekday((CB_Month.Value) & "/1/" & (CB_Year.Value))), _
((CB_Month.Value) & "/1/" & (CB_Year.Value))), "d/mm/yyyy")
ElseIf i >= Weekday((CB_Month.Value) & "/1/" & (CB_Year.Value)) Then
Controls("D" & (i)).Caption = Format(DateAdd("d", (i - Weekday((CB_Month.Value) & "/1/" & (CB_Year.Value))), _
((CB_Month.Value) & "/1/" & (CB_Year.Value))), "d")
Controls("D" & (i)).ControlTipText = Format(DateAdd("d", (i - Weekday((CB_Month.Value) & "/1/" & (CB_Year.Value))), _
((CB_Month.Value) & "/1/" & (CB_Year.Value))), "d/mm/yyyy")
End If
Next
End Sub

Related

Trouble with this macro :(

I've been trying to program a special user login and Audit Trail, the login makes sheets display in custom order, then I still get
Error 1004: Method of Visible Object Failed.
Help me please :(
Macro 1 (I have 5 sheets in this book, each one has this macro in them):
Private Sub Worksheet_Deactivate()
Me.Name = "Información"
ThisWorkbook.Protect , True
Application.OnTime Now, "UnprotectBook"
End Sub
And Have this one in This Workbook:
Private Sub Workbook_Open()
Application.Visible = False
Sheet1.Visible = True
Sheet2.Visible = False
Sheet3.Visible = False
Sheet4.Visible = False
Sheet5.Visible = False
UF_log.Show
End Sub
Private Sub Workbook_Close()
Sheet1.Visible = False
Sheet2.Visible = False
Sheet3.Visible = False
Sheet4.Visible = False
Sheet5.Visible = False
End Sub
Private Sub Workbook_NewSheet(ByVal Sh As Object)
Application.DisplayAlerts = False
ActiveSheet.Delete
MsgBox "No se tiene permitido insertar nuevas hojas de cálculo", vbExclamation, "Alerta"
Application.DisplayAlerts = True
End Sub
UF log code:
Private Sub EnterButton_Click()
Dim Fila, final As Integer
Dim password As Variant
Dim DatoEncontrado
UsuarioExistente = Application.WorksheetFunction.CountIf(Sheets("Users").Range("A:A"), _
Me.TxtUser.Value)
Set Rango = Sheets("Users").Range("A:A")
If Trim(TxtUser.Text) = "" Then
MsgBox "Ingreso Usuario", vbExclamation, "Alerta"
TxtUser.SetFocus
Exit Sub
End If
If Trim(TxtPassword.Text) = "" Then
MsgBox "Ingreso Contraseña", vbExclamation, "Alerta"
TxtPassword.SetFocus
Exit Sub
End If
If UsuarioExistente = 0 Then
MsgBox "El usuario '" & Me.TxtUser & "' no existe", vbExclamation, "Alerta"
Exit Sub
End If
If UsuarioExistente = 1 Then
DatoEncontrado = Rango.Find(What:=Me.TxtUser.Value, MatchCase:=True).Address
Contra = CStr(Sheets("Users").Range(DatoEncontrado).Offset(0, 1).Value)
Estatus = CStr(Sheets("Users").Range(DatoEncontrado).Offset(0, 2).Value)
If Sheets("Users").Range(DatoEncontrado).Value = Me.TxtUser.Value And Contra = Me.TxtPassword.Value Then
MsgBox "Acceso correcto", vbExclamation, "Ok"
If Estatus = "Administrador" Then
Application.Visible = True
Sheet1.Visible = True
Sheet2.Visible = True
Sheet3.Visible = True
Sheet4.Visible = True
Sheet5.Visible = True
Application.CommandBars("Ply").Enabled = True
Call Desproteger
For Fila = 1 To 1000
If Sheet4.Cells(Fila, 1) = "" Then
final = Fila
Exit For
End If
Next
Sheet4.Cells(final, 1) = Application.UserName & " accessed via log in " & " at " & Time & " " & Date
Call Proteger
End
Else
If Estatus = "Fabricación" Then
Application.Visible = True
Sheet1.Visible = True
Sheet2.Visible = xlSheetVeryHidden
Sheet3.Visible = True
Sheet4.Visible = True
Sheet5.Visible = xlSheetVeryHidden
Application.CommandBars("Ply").Enabled = True
Call Desproteger
For Fila = 1 To 1000
If Sheet4.Cells(Fila, 1) = "" Then
final = Fila
Exit For
End If
Next
Sheet4.Cells(final, 1) = Application.UserName & " accessed via log in " & " at " & Time & " " & Date
Call Proteger
End
Else
Application.Visible = True
Sheet1.Visible = True
Sheet2.Visible = True
Sheet3.Visible = xlSheetVeryHidden
Sheet4.Visible = True
Sheet5.Visible = xlSheetVeryHidden
Application.CommandBars("Ply").Enabled = False
Call Desproteger
For Fila = 1 To 1000
If Sheet4.Cells(Fila, 1) = "" Then
final = Fila
Exit For
End If
Next
Sheet4.Cells(final, 1) = Application.UserName & " accessed via log in " & " at " & Time & " " & Date
Call Proteger
End
End If
End If
Else
MsgBox "Datos incorrectos, vuelva a intentar", vbExclamation, "Error"
End If
End If
End Sub
Private Sub ExitButton_Click()
End
End Sub

Macro Optimization ifs seem to slow it down a lat

I would love to optimize this code so that it executes faster...
Sub gotocfstatement()
If ActiveCell.Row < 10 Then Exit Sub
If ActiveCell.Row > 5001 Then Exit Sub
If Sheet1.Range("p" & (ActiveCell.Row)).Value = "" Then Exit Sub
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Filename = Sheet1.Range("p" & (ActiveCell.Row)).Value
Sheet2.Range("b9").Value = Filename
If Sheet2.Range("b15").Value = "" Then
Sheet2.Range("b14").Value = Sheet2.Range("s1").Value
Else
Sheet2.Range("b14").Value = Sheet2.Range("b15").Value
End If
If Sheet2.Range("a81").Value = "" Then
Sheet2.Range("a85").Value = Sheet2.Range("ab1").Value
Else
Sheet2.Range("a85").Value = Sheet2.Range("a81").Value
End If
Sheets("cash flow statement").Select
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
End Sub

Interactive Excel Calendar

I want to make an excel calendar interactive. When I click on a day, I want it to take the user to a new box/screen/cell where they can see a day schedule instead of the default month schedule.
I know I can hyperlink each cell to another cell on a different page but that would be very tedious. How can I automate this?
You can link the cell so when a user clicks into it, normally toggling the cell to be changed, it instead takes triggers an event. Here is some code that will trigger an event when a desired cell is selected posted by "iwrk4dedpr" on ozgrid.com. As for the actual code you would input to take the user to a new sheet with all the days events on it, well you specifically asked me to not tell you the answer. Have Fun looking/Learning!
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Do something if Cell(1,1) or Range("A1") has been selected
if target.row = 1 and target.column = 1 then
' your code in here
end if
End Sub
You can try:
Option Explicit
Dim ThisDay As Date
Dim ThisYear, ThisMth As Date
Dim CreateCal As Boolean
Dim i As Integer
Private Sub HelpLabel_Click()
End Sub
Private Sub UserForm_Initialize()
Application.EnableEvents = False
'starts the form on todays date
ThisDay = Date
ThisMth = Format(ThisDay, "mm")
ThisYear = Format(ThisDay, "yyyy")
For i = 1 To 12
CB_Mth.AddItem Format(DateSerial(Year(Date), Month(Date) + i, 0), "mmmm")
Next
CB_Mth.ListIndex = Format(Date, "mm") - Format(Date, "mm")
For i = -20 To 50
If i = 1 Then CB_Yr.AddItem Format((ThisDay), "yyyy") Else CB_Yr.AddItem _
Format((DateAdd("yyyy", (i - 1), ThisDay)), "yyyy")
Next
CB_Yr.ListIndex = 21
'Builds the calendar with todays date
CalendarFrm.Width = CalendarFrm.Width
CreateCal = True
Call Build_Calendar
Application.EnableEvents = True
End Sub
Private Sub CB_Mth_Change()
'rebuilds the calendar when the month is changed by the user
Build_Calendar
End Sub
Private Sub CB_Yr_Change()
'rebuilds the calendar when the year is changed by the user
Build_Calendar
End Sub
Private Sub Build_Calendar()
'the routine that actually builds the calendar each time
If CreateCal = True Then
CalendarFrm.Caption = " " & CB_Mth.Value & " " & CB_Yr.Value
'sets the focus for the todays date button
CommandButton1.SetFocus
For i = 1 To 42
If i < Weekday((CB_Mth.Value) & "/1/" & (CB_Yr.Value)) Then
Controls("D" & (i)).Caption = Format(DateAdd("d", (i - Weekday((CB_Mth.Value) & "/1/" & (CB_Yr.Value))), _
((CB_Mth.Value) & "/1/" & (CB_Yr.Value))), "d")
Controls("D" & (i)).ControlTipText = Format(DateAdd("d", (i - Weekday((CB_Mth.Value) & "/1/" & (CB_Yr.Value))), _
((CB_Mth.Value) & "/1/" & (CB_Yr.Value))), "m/d/yy")
ElseIf i >= Weekday((CB_Mth.Value) & "/1/" & (CB_Yr.Value)) Then
Controls("D" & (i)).Caption = Format(DateAdd("d", (i - Weekday((CB_Mth.Value) _
& "/1/" & (CB_Yr.Value))), ((CB_Mth.Value) & "/1/" & (CB_Yr.Value))), "d")
Controls("D" & (i)).ControlTipText = Format(DateAdd("d", (i - Weekday((CB_Mth.Value) & "/1/" & (CB_Yr.Value))), _
((CB_Mth.Value) & "/1/" & (CB_Yr.Value))), "m/d/yy")
End If
If Format(DateAdd("d", (i - Weekday((CB_Mth.Value) & "/1/" & (CB_Yr.Value))), _
((CB_Mth.Value) & "/1/" & (CB_Yr.Value))), "mmmm") = ((CB_Mth.Value)) Then
If Controls("D" & (i)).BackColor <> &H80000016 Then Controls("D" & (i)).BackColor = &H80000018 '&H80000010
Controls("D" & (i)).Font.Bold = True
If Format(DateAdd("d", (i - Weekday((CB_Mth.Value) & "/1/" & (CB_Yr.Value))), _
((CB_Mth.Value) & "/1/" & (CB_Yr.Value))), "m/d/yy") = Format(ThisDay, "m/d/yy") Then Controls("D" & (i)).SetFocus
Else
If Controls("D" & (i)).BackColor <> &H80000016 Then Controls("D" & (i)).BackColor = &H8000000F
Controls("D" & (i)).Font.Bold = False
End If
Next
End If
End Sub
Private Sub D1_Click()
'this sub and the ones following represent the buttons for days on the form
'retrieves the current value of the individual controltiptext and
'places it in the active cell
ActiveCell.Value = D1.ControlTipText
Unload Me
'after unload you can call a different userform to continue data entry
'uncomment this line and add a userform named UserForm2
'Userform2.Show
End Sub
Private Sub D2_Click()
ActiveCell.Value = D2.ControlTipText
Unload Me
End Sub
Private Sub D3_Click()
ActiveCell.Value = D3.ControlTipText
Unload Me
End Sub
Private Sub D4_Click()
ActiveCell.Value = D4.ControlTipText
Unload Me
End Sub
Private Sub D5_Click()
ActiveCell.Value = D5.ControlTipText
Unload Me
End Sub
Private Sub D6_Click()
ActiveCell.Value = D6.ControlTipText
Unload Me
End Sub
Private Sub D7_Click()
ActiveCell.Value = D7.ControlTipText
Unload Me
End Sub
Private Sub D8_Click()
ActiveCell.Value = D8.ControlTipText
Unload Me
End Sub
Private Sub D9_Click()
ActiveCell.Value = D9.ControlTipText
Unload Me
End Sub
Private Sub D10_Click()
ActiveCell.Value = D10.ControlTipText
Unload Me
End Sub
Private Sub D11_Click()
ActiveCell.Value = D11.ControlTipText
Unload Me
End Sub
Private Sub D12_Click()
ActiveCell.Value = D12.ControlTipText
Unload Me
End Sub
Private Sub D13_Click()
ActiveCell.Value = D13.ControlTipText
Unload Me
End Sub
Private Sub D14_Click()
ActiveCell.Value = D14.ControlTipText
Unload Me
End Sub
Private Sub D15_Click()
ActiveCell.Value = D15.ControlTipText
Unload Me
End Sub
Private Sub D16_Click()
ActiveCell.Value = D16.ControlTipText
Unload Me
End Sub
Private Sub D17_Click()
ActiveCell.Value = D17.ControlTipText
Unload Me
End Sub
Private Sub D18_Click()
ActiveCell.Value = D18.ControlTipText
Unload Me
End Sub
Private Sub D19_Click()
ActiveCell.Value = D19.ControlTipText
Unload Me
End Sub
Private Sub D20_Click()
ActiveCell.Value = D20.ControlTipText
Unload Me
End Sub
Private Sub D21_Click()
ActiveCell.Value = D21.ControlTipText
Unload Me
End Sub
Private Sub D22_Click()
ActiveCell.Value = D22.ControlTipText
Unload Me
End Sub
Private Sub D23_Click()
ActiveCell.Value = D23.ControlTipText
Unload Me
End Sub
Private Sub D24_Click()
ActiveCell.Value = D24.ControlTipText
Unload Me
End Sub
Private Sub D25_Click()
ActiveCell.Value = D25.ControlTipText
Unload Me
End Sub
Private Sub D26_Click()
ActiveCell.Value = D26.ControlTipText
Unload Me
End Sub
Private Sub D27_Click()
ActiveCell.Value = D27.ControlTipText
Unload Me
End Sub
Private Sub D28_Click()
ActiveCell.Value = D28.ControlTipText
Unload Me
End Sub
Private Sub D29_Click()
ActiveCell.Value = D29.ControlTipText
Unload Me
End Sub
Private Sub D30_Click()
ActiveCell.Value = D30.ControlTipText
Unload Me
End Sub
Private Sub D31_Click()
ActiveCell.Value = D31.ControlTipText
Unload Me
End Sub
Private Sub D32_Click()
ActiveCell.Value = D32.ControlTipText
Unload Me
End Sub
Private Sub D33_Click()
ActiveCell.Value = D33.ControlTipText
Unload Me
End Sub
Private Sub D34_Click()
ActiveCell.Value = D34.ControlTipText
Unload Me
End Sub
Private Sub D35_Click()
ActiveCell.Value = D35.ControlTipText
Unload Me
End Sub
Private Sub D36_Click()
ActiveCell.Value = D36.ControlTipText
Unload Me
End Sub
Private Sub D37_Click()
ActiveCell.Value = D37.ControlTipText
Unload Me
End Sub
Private Sub D38_Click()
ActiveCell.Value = D38.ControlTipText
Unload Me
End Sub
Private Sub D39_Click()
ActiveCell.Value = D39.ControlTipText
Unload Me
End Sub
Private Sub D40_Click()
ActiveCell.Value = D40.ControlTipText
Unload Me
End Sub
Private Sub D41_Click()
ActiveCell.Value = D41.ControlTipText
Unload Me
End Sub
Private Sub D42_Click()
ActiveCell.Value = D42.ControlTipText
Unload Me
End Sub

Run-Time error '-2147221080 (800401a8)' Method 'Worksheets' of object '_Workbook' failed

I have a useform that will open another work book when opened and close the workbook when closed. This works well the first time, but when I go to open the userform again it shoots out the runtime error. I can use some help on this issue I have not been able to determine what the issue is. Below is the error line in italics:
Sub Auto_Open()
Application.OnKey "{F3}", "ShowForm"
End Sub
Sub ShowForm()
*Auto_Fill_Form.Show*
End Sub
The button I use to exit the userform is shown below:
Private Sub CommandButton4_Click()
Workbooks("WorkOrderDatabase.xlsm").Close SaveChanges:=True
Unload Me
End Sub
Userform Code:
Private Sub CommandButton2_Click()
Call UserForm_Initialize
End Sub
Private Sub CommandButton4_Click()
'ComboBox1.Value = ""
Workbooks("WorkOrderDatabase.xlsm").Close SaveChanges:=True
Unload Me
End Sub
Private Sub CommandButton5_Click()
Me.Width = 480
Me.Height = 520
Auto_Fill_Form.Label26.Visible = True
Auto_Fill_Form.TextBox15.Visible = True
Auto_Fill_Form.CommandButton7.Visible = True
Auto_Fill_Form.Label22.Visible = False
Auto_Fill_Form.TextBox16.Visible = False
Auto_Fill_Form.Label23.Visible = False
Auto_Fill_Form.TextBox17.Visible = False
Auto_Fill_Form.Label24.Visible = False
Auto_Fill_Form.TextBox18.Visible = False
Auto_Fill_Form.Label25.Visible = False
Auto_Fill_Form.TextBox19.Visible = False
Auto_Fill_Form.CommandButton8.Visible = False
TextBox15 = Translate(TextBox10.Value, "en", "es", True)
SortAsc2
End Sub
Private Sub CommandButton6_Click()
Me.Width = 480
Me.Height = 520
Auto_Fill_Form.Label22.Visible = True
Auto_Fill_Form.TextBox16.Visible = True
Auto_Fill_Form.Label23.Visible = True
Auto_Fill_Form.TextBox17.Visible = True
Auto_Fill_Form.Label24.Visible = True
Auto_Fill_Form.TextBox18.Visible = True
Auto_Fill_Form.Label25.Visible = True
Auto_Fill_Form.TextBox19.Visible = True
Auto_Fill_Form.CommandButton8.Visible = True
Auto_Fill_Form.Label26.Visible = False
Auto_Fill_Form.TextBox15.Visible = False
Auto_Fill_Form.CommandButton7.Visible = False
TextBox16 = Translate(TextBox11.Value, "en", "es", True)
TextBox17 = Translate(TextBox12.Value, "en", "es", True)
TextBox18 = Translate(TextBox13.Value, "en", "es", True)
TextBox19 = Translate(TextBox14.Value, "en", "es", True)
End Sub
Private Sub CommandButton7_Click()
Dim rng As Range
Set rng = Locations.Worksheets(Page).ListObjects("Table15").Range
Dim LastRow As Long
LastRow = rng.Find(What:="*", _
After:=rng.Cells(1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
rng.Parent.Cells(LastRow + 1, 1).Value = TextBox10.Value
rng.Parent.Cells(LastRow + 1, 2).Value = TextBox15.Value
SortAsc2
End Sub
Private Sub CommandButton8_Click()
Dim rng As Range
Set rng = Locations.Worksheets(Page).ListObjects("Table24").Range
Dim LastRow As Long
LastRow = rng.Find(What:="*", _
After:=rng.Cells(1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
rng.Parent.Cells(LastRow + 1, 4).Value = TextBox11.Value
rng.Parent.Cells(LastRow + 1, 5).Value = TextBox12.Value
rng.Parent.Cells(LastRow + 1, 6).Value = TextBox13.Value
rng.Parent.Cells(LastRow + 1, 7).Value = TextBox14.Value
rng.Parent.Cells(LastRow + 1, 8).Value = TextBox16.Value
rng.Parent.Cells(LastRow + 1, 9).Value = TextBox17.Value
rng.Parent.Cells(LastRow + 1, 10).Value = TextBox18.Value
rng.Parent.Cells(LastRow + 1, 11).Value = TextBox19.Value
SortAsc2
End Sub
Private Sub OkButton_Click()
ThisWorkbook.Sheets("WO_Cover").Cells(1, 9).Value = TextBox1.Value
ThisWorkbook.Sheets("First Piece Inspection").Cells(5, 7).Value = TextBox1.Value
ThisWorkbook.Sheets("Production Inspection").Cells(5, 7).Value = TextBox1.Value
ThisWorkbook.Sheets("WO_Cover").Cells(3, 2).Value = TextBox2.Value
ThisWorkbook.Sheets("WO_Cover").Cells(3, 8).Value = TextBox3.Value
ThisWorkbook.Sheets("WO_Cover").Cells(4, 8).Value = TextBox4.Value
ThisWorkbook.Sheets("WO_Cover").Cells(4, 5).Value = TextBox5.Value
ThisWorkbook.Sheets("WO_Cover").Cells(5, 2).Value = ComboBox1.Value
ThisWorkbook.Sheets("WO_Cover").Cells(10, 1).Value = TextBox7.Value
ThisWorkbook.Sheets("WO_Cover").Cells(10, 3).Value = TextBox8.Value
ThisWorkbook.Sheets("WO_Cover").Cells(20, 3).Value = TextBox9.Value
ThisWorkbook.Sheets("WO_Cover").Cells(21, 2).Value = ComboBox2.Value
ThisWorkbook.Sheets("WO_Cover").Cells(24, 2).Value = ComboBox3.Value
ThisWorkbook.Sheets("WO_Cover").Cells(27, 2).Value = ComboBox4.Value
ThisWorkbook.Sheets("WO_Cover").Cells(30, 2).Value = ComboBox5.Value
ThisWorkbook.Sheets("WO_Cover").Cells(33, 2).Value = ComboBox6.Value
ThisWorkbook.Sheets("WO_Cover").Cells(36, 2).Value = ComboBox7.Value
End Sub
Private Sub OptionButton1_Click()
If OptionButton1.Value Then
Me.Width = 375
Me.Height = 520
Auto_Fill_Form.Label17.Visible = True
Auto_Fill_Form.TextBox10.Visible = True
Auto_Fill_Form.CommandButton5.Visible = True
Auto_Fill_Form.Label18.Visible = False
Auto_Fill_Form.TextBox11.Visible = False
Auto_Fill_Form.Label19.Visible = False
Auto_Fill_Form.TextBox12.Visible = False
Auto_Fill_Form.Label20.Visible = False
Auto_Fill_Form.TextBox13.Visible = False
Auto_Fill_Form.Label21.Visible = False
Auto_Fill_Form.TextBox14.Visible = False
Auto_Fill_Form.CommandButton6.Visible = False
Else
Me.Width = 250
Me.Height = 520
Auto_Fill_Form.Label17.Visible = False
Auto_Fill_Form.TextBox10.Visible = False
Auto_Fill_Form.CommandButton5.Visible = False
End If
End Sub
Private Sub OptionButton2_Click()
If OptionButton2.Value Then
Me.Width = 375
Me.Height = 520
Auto_Fill_Form.Label18.Visible = True
Auto_Fill_Form.TextBox11.Visible = True
Auto_Fill_Form.Label19.Visible = True
Auto_Fill_Form.TextBox12.Visible = True
Auto_Fill_Form.Label20.Visible = True
Auto_Fill_Form.TextBox13.Visible = True
Auto_Fill_Form.Label21.Visible = True
Auto_Fill_Form.TextBox14.Visible = True
Auto_Fill_Form.CommandButton6.Visible = True
Auto_Fill_Form.Label17.Visible = False
Auto_Fill_Form.TextBox10.Visible = False
Auto_Fill_Form.CommandButton5.Visible = False
Else
Me.Width = 250
Me.Height = 520
Auto_Fill_Form.Label18.Visible = False
Auto_Fill_Form.TextBox11.Visible = False
Auto_Fill_Form.Label19.Visible = False
Auto_Fill_Form.TextBox12.Visible = False
Auto_Fill_Form.Label20.Visible = False
Auto_Fill_Form.TextBox13.Visible = False
Auto_Fill_Form.Label21.Visible = False
Auto_Fill_Form.TextBox14.Visible = False
Auto_Fill_Form.CommandButton6.Visible = False
End If
End Sub
Private Sub UserForm_Activate()
TextBox1.Value = ThisWorkbook.Sheets("WO_Cover").Cells(1, 9).Value
TextBox2.Value = ThisWorkbook.Sheets("WO_Cover").Cells(3, 2).Value
TextBox3.Value = ThisWorkbook.Sheets("WO_Cover").Cells(3, 8).Value
TextBox4.Value = ThisWorkbook.Sheets("WO_Cover").Cells(4, 8).Value
'TextBox5.Value = ThisWorkbook.Sheets("WO_Cover").Cells(4, 5).Value
ComboBox1.Value = ThisWorkbook.Sheets("WO_Cover").Cells(5, 2).Value
TextBox7.Value = ThisWorkbook.Sheets("WO_Cover").Cells(10, 1).Value
TextBox8.Value = ThisWorkbook.Sheets("WO_Cover").Cells(10, 3).Value
TextBox9.Value = ThisWorkbook.Sheets("WO_Cover").Cells(20, 3).Value
ComboBox2.Value = ThisWorkbook.Sheets("WO_Cover").Cells(21, 2).Value
ComboBox3.Value = ThisWorkbook.Sheets("WO_Cover").Cells(24, 2).Value
ComboBox4.Value = ThisWorkbook.Sheets("WO_Cover").Cells(27, 2).Value
ComboBox5.Value = ThisWorkbook.Sheets("WO_Cover").Cells(30, 2).Value
ComboBox6.Value = ThisWorkbook.Sheets("WO_Cover").Cells(33, 2).Value
ComboBox7.Value = ThisWorkbook.Sheets("WO_Cover").Cells(36, 2).Value
Auto_Fill_Form.Label17.Visible = False
Auto_Fill_Form.TextBox10.Visible = False
Auto_Fill_Form.Label18.Visible = False
Auto_Fill_Form.TextBox11.Visible = False
Auto_Fill_Form.Label19.Visible = False
Auto_Fill_Form.TextBox12.Visible = False
Auto_Fill_Form.Label20.Visible = False
Auto_Fill_Form.TextBox13.Visible = False
Auto_Fill_Form.Label21.Visible = False
Auto_Fill_Form.TextBox14.Visible = False
Auto_Fill_Form.CommandButton5.Visible = False
Auto_Fill_Form.CommandButton6.Visible = False
Auto_Fill_Form.Label26.Visible = False
Auto_Fill_Form.TextBox15.Visible = False
Auto_Fill_Form.CommandButton7.Visible = False
Auto_Fill_Form.Label22.Visible = False
Auto_Fill_Form.TextBox16.Visible = False
Auto_Fill_Form.Label23.Visible = False
Auto_Fill_Form.TextBox17.Visible = False
Auto_Fill_Form.Label24.Visible = False
Auto_Fill_Form.TextBox18.Visible = False
Auto_Fill_Form.Label25.Visible = False
Auto_Fill_Form.TextBox19.Visible = False
Auto_Fill_Form.CommandButton8.Visible = False
'TextBox10.Value =
End Sub
Private Sub UserForm_Initialize()
'Empty Form
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
ComboBox1.Value = Null
'Initialized value
TextBox5.Value = "A"
ComboBox2.Value = "N/A"
ComboBox3.Value = "N/A"
ComboBox4.Value = "N/A"
ComboBox5.Value = "N/A"
ComboBox6.Value = "N/A"
ComboBox7.Value = "N/A"
Me.ComboBox1.List = Locations.Worksheets(Page).ListObjects("Table15").ListColumns(1).DataBodyRange.Value
Me.ComboBox2.List = Locations.Worksheets(Page).ListObjects("Table24").ListColumns(1).DataBodyRange.Value
Me.ComboBox3.List = Locations.Worksheets(Page).ListObjects("Table24").ListColumns(1).DataBodyRange.Value
Me.ComboBox4.List = Locations.Worksheets(Page).ListObjects("Table24").ListColumns(1).DataBodyRange.Value
Me.ComboBox5.List = Locations.Worksheets(Page).ListObjects("Table24").ListColumns(1).DataBodyRange.Value
Me.ComboBox6.List = Locations.Worksheets(Page).ListObjects("Table24").ListColumns(1).DataBodyRange.Value
Me.ComboBox7.List = Locations.Worksheets(Page).ListObjects("Table24").ListColumns(1).DataBodyRange.Value
TextBox7.Value = ""
TextBox8.Value = ""
TextBox9.Value = ""
End Sub
Module 1:
Private wLocations As Workbook
Public Const Page = "Description - Processes"
Public Property Get Locations() As Workbook
Const sPath As String = "V:\My Stuff\Templates\Work Order Batch Creation Template\WorkOrderDatabase.xlsm"
Dim sFile As String
If wLocations Is Nothing Then
'extract file name from full path
sFile = Dir(sPath)
On Error Resume Next
'check if the file is already open
Set wLocations = Workbooks(sFile)
If wLocations Is Nothing Then
Set wLocations = Workbooks.Open(sPath)
End If
On Error GoTo 0
End If
Set Locations = wLocations
End Property
Module 2:
Sub Auto_Open()
Application.OnKey "{F3}", "ShowForm"
End Sub
Sub ShowForm()
Auto_Fill_Form.Show
End Sub
Module 3:
Sub SortAsc2()
Locations.Worksheets(Page).Range("A2:B16").Sort Key1:=Locations.Worksheets(Page).Range("A2"), _
Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
Locations.Worksheets(Page).Range("D2:K16").Sort Key1:=Locations.Worksheets(Page).Range("D2"), _
Order1:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
' Locations.Worksheets("Description - Processes").Range("A2:B16").Sort Key1:=Locations.Worksheets("Description - Processes").Range("A2"), _
' Order1:=xlDescending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
' Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
'
' Locations.Worksheets("Description - Processes").Range("D2:K16").Sort Key1:=Locations.Worksheets("Description - Processes").Range("D2"), _
' Order1:=xlDescending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
' Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
End Sub
Module 4:
Public Function Translate(strInput As String, strFromLanguageCode As String, strToLanguageCode As String, blnTargetAlphabet As Boolean) As String
Dim strURL As String
Dim objHTTP As Object
Dim objHTML As Object
Dim objDivs As Object, objDiv
Dim strTranslatedT0 As String
Dim strTranslatedO1 As String
' send query to web page
strURL = "https://translate.google.com/m?hl=" & strFromLanguageCode & _
"&sl=" & strFromLanguageCode & _
"&tl=" & strToLanguageCode & _
"&ie=UTF-8&prev=_m&q=" & strInput
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
objHTTP.Open "GET", strURL, False
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.send ""
' create a html document
Set objHTML = CreateObject("htmlfile")
With objHTML
.Open
.Write objHTTP.responseText
.Close
End With
' o1 has Anglicised translation, t0 as tranlsation in target language
Set objDivs = objHTML.getElementsByTagName("div")
For Each objDiv In objDivs
If objDiv.className = "o1" Then
strTranslatedO1 = objDiv.innerText
End If
If objDiv.className = "t0" Then
strTranslatedT0 = objDiv.innerText
End If
Next objDiv
' choose which to return
If blnTargetAlphabet Then
Translate = strTranslatedT0
Else
Translate = strTranslatedO1
End If
CleanUp:
Set objHTML = Nothing
Set objHTTP = Nothing
End Function
Open the workbook to collect the data.
If you close the wb right away, you will have to get rid of the workbook.close line in the "Quit" Button
Private Sub UserForm_Initialize()
Dim wb As Workbook
Set wb = Workbooks.Open("C:\Users\dmorrison\Downloads\TestRemoveLater\WorkOrderDatabase-1.xlsm")
'Empty Form
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
ComboBox1.Value = Null
'Initialized value
TextBox5.Value = "A"
ComboBox2.Value = "N/A"
ComboBox3.Value = "N/A"
ComboBox4.Value = "N/A"
ComboBox5.Value = "N/A"
ComboBox6.Value = "N/A"
ComboBox7.Value = "N/A"
With wb
Me.ComboBox1.List = .Worksheets(Page).ListObjects("Table15").ListColumns(1).DataBodyRange.Value
Me.ComboBox2.List = .Worksheets(Page).ListObjects("Table24").ListColumns(1).DataBodyRange.Value
Me.ComboBox3.List = .Worksheets(Page).ListObjects("Table24").ListColumns(1).DataBodyRange.Value
Me.ComboBox4.List = .Worksheets(Page).ListObjects("Table24").ListColumns(1).DataBodyRange.Value
Me.ComboBox5.List = .Worksheets(Page).ListObjects("Table24").ListColumns(1).DataBodyRange.Value
Me.ComboBox6.List = .Worksheets(Page).ListObjects("Table24").ListColumns(1).DataBodyRange.Value
Me.ComboBox7.List = .Worksheets(Page).ListObjects("Table24").ListColumns(1).DataBodyRange.Value
'.close
End With
TextBox7.Value = ""
TextBox8.Value = ""
TextBox9.Value = ""
End Sub

ByRef argument type mismatch:

ByRef argument type mismatch when running the fileconv.xla add-in in Excel 97.
The reason I need this to work is because I need to convert ~100 Lotus 1-2-3 files from wk* to xls.
The term highlighted in VBA when I compile is marked by double asteriks in the separated code:
Workbooks.Open Filename:=PathFile(**p_FileInfo**(i, 3), p_FileInfo(i, 4)), ReadOnly:=True, Password:="password"
Sub FinishSub()
Dim TestOpen As Boolean
Dim DirDest As String
Application.ScreenUpdating = False
CreateDir "wzkfpbdxwzkfpbdxwzkfpbdx"
If Not (DirCreated) Then
Application.ScreenUpdating = True
Exit Sub
End If
If Len(dlg.DropDowns("DriveDD").List(dlg.DropDowns("DriveDD").ListIndex)) <> 2 Then
DirDest = Right(dlg.DropDowns("DriveDD").List(dlg.DropDowns("DriveDD").ListIndex), _
Len(dlg.DropDowns("DriveDD").List(dlg.DropDowns("DriveDD").ListIndex)) - 3) & _
Right(FullPath, Len(FullPath) - 2)
Else
DirDest = dlg.DropDowns("DriveDD").List(dlg.DropDowns("DriveDD").ListIndex) & _
Right(FullPath, Len(FullPath) - 2)
End If
Set wbResult = Workbooks.Add
ActiveCell.Value = LookupString("File")
Range("B1").Value = LookupString("ConvertedTo")
Range("C1").Value = LookupString("Result")
Range("D1").Value = LookupString("Reason")
Range("A2").Select
k = 0
For i = 1 To CountFile
p_FileInfo(i, 5) = DirDest
If p_FileInfo(i, 7) = "yes" Then
k = k + 1
On Error GoTo ErrorOpen
Success = "True"
ErrorMsg = ""
SetWaitCursor True
If TestIfWorkbookIsOpen(p_FileInfo(i, 4)) Then Workbooks(p_FileInfo(i, 4)).Close saveChanges:=False
Application.StatusBar = LookupString("Opening") & p_FileInfo(i, 4) & "(" & k & "/" & CountFileToConvert & ")"
Application.DisplayAlerts = False
Workbooks.Open Filename:=PathFile(**p_FileInfo**(i, 3), p_FileInfo(i, 4)), ReadOnly:=True, Password:="password"
On Error GoTo 0
On Error Resume Next
Application.StatusBar = LookupString("Saving") & p_FileInfo(i, 6) & "(" & k & "/" & CountFileToConvert & ")"
' Check if the XLS filename already exists.
FindFileName
Workbooks(p_FileInfo(i, 4)).SaveAs Filename:=PathFile(p_FileInfo(i, 5), p_FileInfo(i, 6)), FileFormat:=xlNormal
'Application.StatusBar = False
Workbooks(p_FileInfo(i, 4)).Close saveChanges:=False
Workbooks(p_FileInfo(i, 6)).Close saveChanges:=False
SaveIsSuccess Success
SetWaitCursor False
On Error GoTo 0
End If
Next i
SaveIsSuccess "End"
Application.StatusBar = False
Application.ScreenUpdating = True
Exit Sub
ErrorOpen: ' Error-handling routine.
Select Case Err ' Evaluate Error Number.
Case 18
TestMsgBox = MsgBox(LookupString("UserInterruption", "AlertTable"), vbYesNo)
If TestMsgBox = vbYes Then
On Error Resume Next
Application.StatusBar = False
Workbooks(p_FileInfo(i, 4)).Close saveChanges:=False
Workbooks(p_FileInfo(i, 6)).Close saveChanges:=False
Application.ScreenUpdating = True
Exit Sub
On Error GoTo 0
Else
Resume Next
End If
Case 1004
SetWaitCursor False
Set dlg = ThisWorkbook.DialogSheets("Password")
dlg.DialogFrame.Characters.Text = p_FileInfo(i, 4)
If TryAgain = False Then
dlg.TextBoxes("PassTB").Text = LookupString("IsProtected", "AlertTable")
dlg.EditBoxes("PassEB").Text = ""
Else
dlg.TextBoxes("PassTB").Text = LookupString("InvalidPassword", "AlertTable")
End If
ShowTest = dlg.Show
Select Case ShowTest
Case True
Resume
Case False
Success = "False"
ErrorMsg = Error()
Resume Next
End Select
SetWaitCursor True
End Select
Application.StatusBar = False
End Sub
I assume you have this
Public Function PathFile(ByRef a As String, ByRef b As String)
PathFile = "C:\Bla.txt"
End Function
and p_FileInfo is an Array, so in this case you have to call the function like this:
Workbooks.Open Filename:=PathFile(CStr(p_FileInfo(i, 3)), CStr(p_FileInfo(i, 4))), ReadOnly:=True, Password:="password"
That should work if I am not misunderstand your question.

Resources