Hi All
I am looking to use a comand button on a excel sheet to search for a code within that sheet then do a vlookup in a folder to call up the required excel workbook.
ok this is what i have, hope i explain it ok.
Private Sub CommandButton1_Click()
Dim CODE As String
CODE = Range("N3").Text 'Look in N3 for the code.
MsgBox "THE CODE IS " & (CODE) ' Show the code'
Dim DirFile As String
DirFile = "Q\PDomain\QM\Quality Notes" & (CODE) & ".xls" 'Look in the Q Drive,QM,Quality Notes folder for the excel sheet with the code name.
If Dir(DirFile) = "" Then
MsgBox "No special notes file found for that part" ' if there is no file display this message.
Else
Workbooks.Open Filename:=DirFile
ans = MsgBox("Here are the special care notes for that part. Would you like to print it ?", vbYesNo) ' if there is open and ask if you want to print.
If ans = vbYes Then
'MsgBox "You picked yes, I will now print the sheet !"
ActiveWorkbook.PrintOut Copies:=1, Collate:=True
MsgBox "Please ensure the Special Notes sheet is placed with the route card and is visible to the operator !" ' after printing give an instruction
End If
End If
'MsgBox "All action is completed"
End Sub
Any direction to where i am going wrong would be great.hope i have given enough information. I did start off be drawing the command box and double clicking the box to enter code.
<colgroup><col width="64"></colgroup><tbody>
[TD="width: 64"][/TD]
</tbody>
cheers
Ray
I am looking to use a comand button on a excel sheet to search for a code within that sheet then do a vlookup in a folder to call up the required excel workbook.
ok this is what i have, hope i explain it ok.
Private Sub CommandButton1_Click()
Dim CODE As String
CODE = Range("N3").Text 'Look in N3 for the code.
MsgBox "THE CODE IS " & (CODE) ' Show the code'
Dim DirFile As String
DirFile = "Q\PDomain\QM\Quality Notes" & (CODE) & ".xls" 'Look in the Q Drive,QM,Quality Notes folder for the excel sheet with the code name.
If Dir(DirFile) = "" Then
MsgBox "No special notes file found for that part" ' if there is no file display this message.
Else
Workbooks.Open Filename:=DirFile
ans = MsgBox("Here are the special care notes for that part. Would you like to print it ?", vbYesNo) ' if there is open and ask if you want to print.
If ans = vbYes Then
'MsgBox "You picked yes, I will now print the sheet !"
ActiveWorkbook.PrintOut Copies:=1, Collate:=True
MsgBox "Please ensure the Special Notes sheet is placed with the route card and is visible to the operator !" ' after printing give an instruction
End If
End If
'MsgBox "All action is completed"
End Sub
Any direction to where i am going wrong would be great.hope i have given enough information. I did start off be drawing the command box and double clicking the box to enter code.
<colgroup><col width="64"></colgroup><tbody>
[TD="width: 64"][/TD]
</tbody>
cheers
Ray