Need InputBox to input value into another function in VBA

jrake40

New Member
Joined
Nov 22, 2016
Messages
30
I would like to put this inputbox value....

Code:
inboxfldr = InputBox("Enter Outlook Folder Name", "Inbox Alert Folder")

Into the below so that the value that the user input replaces the "GLAM" in the Set FLDR line.



Code:
Sub GetFromInbox()

Dim olApp As Outlook.Application
Dim olNs As Namespace
Dim Fldr As MAPIFolder
Dim olMail As Variant
Dim DateCount As Integer
Dim myDate1 As Date
Dim myDate2 As Date


Dim item As Object
Dim doClip As MSForms.DataObject
Dim xlApp As Object ' Excel.Application
Dim xlWkb As Object


Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox).Folders("[U]GLAM[/U]")
Set doClip = New MSForms.DataObject


x = Date
myDate1 = Sheets("Inbox Alerts").Range("A1").Value
myDate2 = Sheets("Inbox Alerts").Range("B1").Value


For Each olMail In Fldr.Items
    If DateSerial(Year(olMail.ReceivedTime), Month(olMail.ReceivedTime), Day(olMail.ReceivedTime)) >= myDate1 And _
       DateSerial(Year(olMail.ReceivedTime), Month(olMail.ReceivedTime), Day(olMail.ReceivedTime)) <= myDate2 And _
       InStr(olMail.Subject, "Alert") >= 0 _
    Then
        doClip.SetText olMail.Body
        doClip.PutInClipboard
        
        Sheets("Inbox Alerts").Cells(Rows.count, 1).End(xlUp).Offset(1, 0).PasteSpecial "Text"
       DateCount = DateCount + 1
    End If
Next olMail


Set Fldr = Nothing
Set olNs = Nothing
Set olApp = Nothing
End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
You obviously need that input box before that Set statement.
Then it would just be:
Code:
Set Fldr = olNs.GetDefaultFolder(olFolderInbox).Folders(inboxfldr)
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,539
Members
449,088
Latest member
RandomExceller01

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