Subjectfilter as Reference not String

Dave_Holland89

New Member
Joined
Jan 18, 2018
Messages
5
Hello All

Hopefully this will be a nice easy one for someone, but I just can't seem to work around this one, I'm sure I must be missing something obvious.

I've got a piece of script to download a file from Outlook based on the subject line which currently works fine, providing the subject line is a string as follows (this is an excerpt):


Code:
Dim subjectFilter As String

subjectFilter = "This is The Subject"

This works fine. However in a bid to future proof the application, I want the end user to be able to select from a number of email subjects (there may be up to 15) in a drop down box in Excel.

If I write "This is the Subject" in A1 of my sheet in the same workbook as the macro, and then replace the above with:

Code:
subjectFilter = Application.Workbook("C:\Documents\Daily Reports.xlsm").Worksheet("Master Sheet").Range("A1")

I just get an error - any ideas on how I can have the Macro run from a reference in a cell? I'm guessing it's because the subjectFilter is no longer a String?

Thanks!

Dave
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Code:
subjectFilter = Application.Workbook("C:\Documents\Daily Reports.xlsm").Worksheet("Master Sheet").Range("A1")


try:

Code:
subjectFilter = Application.Workbook("C:\Documents\Daily Reports.xlsm").Worksheet("Master Sheet").Range("A1").[COLOR=#FF0000]Value[/COLOR]
 
Upvote 0
So, the macro you're running is in the same workbook that you're trying to pull the subject text from?

try:
subjectFilter = Activeworkbook.Worksheets("Master Sheet").Range("A1")

or better yet...
create a named range (say "subjectFilter") where your subject filter text will be and you can reference it:
subjectFilter = [subjectFilter]
or
subjectFilter = range("SubjectFilter")
 
Upvote 0
You sir, are correct, many thanks!

Not sure why I was trying to include the file path of a workbook that was already open :eek:. Sorted now

Thanks very much again.

Dave
 
Upvote 0

Forum statistics

Threads
1,215,050
Messages
6,122,868
Members
449,097
Latest member
dbomb1414

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