Linking a VBA button to Excel cell

B

beginner here

I have tried to locate my answer by looking at the questions and answers from
prior posters, but have been unable to locate what I am looking for.

I am looking for a way to combine two results as one, and then look at that
new result in a PDF file, that is named the same. I know how to combine two
results into a new cell, what I do not know how to do is the VBA coding that
needs to be attached so this button can look up the PDF file by the same
name.

Example:

In Excel in cell [B2] you select from a dropdown list say Oregon, and then
in another dropdown list in cell [F2] you select Salem. Then in cell, [G2]
B2 and F2 would be combined to look like this. [Oregon-Salem]

So now, I would click on a button that would go where I store my PDF files,
and find and open the file called Oregon-Salem.

Any help would be appreciated.

Steve
 
B

beginner here

In my haste to get this question up, I didn't re-read what I wrote. I would
like help in writing this code, not for somebody to do it for me.

Sorry about that.

Steve
 
S

Stopher

Do all these joined file names live in the same folder?

If so you could do:

Shell ("[put file path here]"&[joined name here as a variable or cell
reference]&".pdf")

This should open your pdf file.

Stopher
 
B

beginner here

Stopher I have a problem. What am I doing wrong in this code. It seems that
VBA is looking for another ")", but I don't see it in the line of code that
you gave me. BTW thanks so much for anwering my question.

He is the code as I have it now:

Shell ("C:\Program Files\Adobe"& Range("F4").Select& ".pdf")
 
S

Stopher

Another thing

Shell ("C:\Program Files\Adobe\"& Range("F4")& ".pdf")

Need that extra \ in there as well
 
B

beginner here

Thanks for the additional help, but I'm stilling getting an error. This time
it is saying: Invalid procedure call or argument

So here is my present code with the changes:

Shell ("C:\Program Files\Adobe\" & Range("F4") & ".pdf")

Steve
 
S

Stopher

beginner said:
Thanks for the additional help, but I'm stilling getting an error. This time
it is saying: Invalid procedure call or argument

So here is my present code with the changes:

Shell ("C:\Program Files\Adobe\" & Range("F4") & ".pdf")

Steve

Dim newpath as String, sStr as String
newpath = "C:\Program Files\Adobe\"
sStr = ("cmd /c " & newpath & Range("F4") &".pdf"

Call Shell(sStr, vbNormalFocus)

Stole this out of a post by Tom and adopted it for your instance.
 
B

beginner here

Thanks will test this out this morning

Stopher said:
Dim newpath as String, sStr as String
newpath = "C:\Program Files\Adobe\"
sStr = ("cmd /c " & newpath & Range("F4") &".pdf"

Call Shell(sStr, vbNormalFocus)

Stole this out of a post by Tom and adopted it for your instance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top