VBA Immediate Window

leatherhen99

New Member
Joined
Dec 17, 2019
Messages
27
Office Version
  1. 365
Platform
  1. Windows
Good Morning,

I have a written quite a bit of code for a few spreadsheets lately, and with all my research, I've found that I can use the immediate window to check things in my code... I'm LOVING that! Unfortunately, no one has addressed this in their posts or videos...so I'd like to see if someone can provide a way to use the immediate window instead of running/stepping thru the macro...

I have the following code... and sometimes the email will have the full subject (quotes and cell reference), and other times, it won't include the cell reference...

VBA Code:
Sub send_to_supervisor()

'select CRT sheet
    Sheets("CRT").Select
      
'Create the email to send to supervisor to review time
Dim emailApplication As Object
Dim emailItem As Object
Dim strbody As String
Dim sT0 As String
Dim rng As String

sT0 = Range("C17").Value

Set emailApplication = CreateObject("Outlook.Application")
Set emailItem = emailApplication.CreateItem(0)

strbody = "<body style = font-size:11pt; font-family:Calibri.>" & _
"Hi " & Range("b17").Value & ",  <br><br> Please review the <a href=""location"">timesheet</a>" & _
" for final approval.<br><br>" & _
"Thank you,"

On Error Resume Next
    With emailItem
    .To = sT0
    .Subject = "Timesheet Approval " & Range("a2").Value
    .display
    .HTMLBody = strbody & .HTMLBody

    End With
    On Error GoTo 0
    
Set emailItem = Nothing
Set emailApplication = Nothing
ActiveSheet.Shapes("check box 7").OnAction = ""

End Sub

Questions:
1. How do I utilize the immediate window with a "?" to confirm the email subject?
2. Is there another way to verify that's easier than running/stepping thru the code?

Thanks to all who comb thru these posts and provide responses! I really appreciate everyone else's posts and answers! I hope someone else can find this post useful, too!

Thanks, H
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
You can set a breakpoint in the code, or add a Stop line so that the code will stop wherever you need it to, then you can use the immediate window, or locals window, or watch window to examine whatever you need. In many cases you can also simply hover the cursor over a variable/property name to see what its current value is.
 
Upvote 0
if you press ctrl + G for the immediate window, and then paste this new code (I removed the selections out of there and added With Statements. I also added a debug.print line which will put whatever value that is in A2 into the immediate window

VBA Code:
Sub send_to_supervisor()

'select CRT sheet
'Create the email to send to supervisor to review time
Dim emailApplication As Object
Dim emailItem As Object
Dim strbody As String
Dim sT0 As String
Dim rng As String
With Sheets("CRT")
    sT0 = .Range("C17").Value
    Set emailApplication = CreateObject("Outlook.Application")
    Set emailItem = emailApplication.CreateItem(0)
strbody = "<body style = font-size:11pt; font-family:Calibri.>" & _
"Hi " & .Range("b17").Value & ",  <br><br> Please review the <a href=""location"">timesheet</a>" & _
" for final approval.<br><br>" & _
"Thank you,"
On Error Resume Next
    Debug.Print .Range("A2").Value
    With emailItem
    .To = sT0
    .Subject = "Timesheet Approval " & .Range("a2").Value
    .display
    .HTMLBody = strbody & .HTMLBody
    End With
    On Error GoTo 0
Set emailItem = Nothing
Set emailApplication = Nothing
.Shapes("check box 7").OnAction = ""
End With
End Sub
 
Upvote 0
You can do this:

?"Timesheet Approval " & Range("a2").Value

Im not sure that running/stepping through the code is something you should be avoiding to be honest. Thats your code and running through it tells you exactly what it will be doing.
 
Upvote 0
Thank you all for your input! In the example provided, it's pretty easy to just thru the code, but in a few of my macros, it's within a template. I don't like running thru them because I end up having to recreate the template back to the template. I'm sure there's a way to create a "reset" macro, but I'm not that well versed in resetting things quite yet ;). I've still got quite a bit to go to be as proficient as y'all!

Thanks again for all the suggestions!
 
Upvote 0

Forum statistics

Threads
1,214,935
Messages
6,122,337
Members
449,077
Latest member
Jocksteriom

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