How to use comand button to search for a code then do a vlookup in a folder to call you excel workbook

ray12

New Member
Joined
Nov 15, 2015
Messages
1
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
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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