I desperately need help with this. I currently have to highlight the subject and then I have another script that will copy my highlight and search for emails with that subject in the middle pane.
What I want is this:
1. Select the email in the middle pane. (This will be manual and done by the user)
2. Push a hotkey and have the script copy the subject from the email (This is what I need help with)
3. Have the copied email subject pasted in the search bar in the middle pane (I already have this part of the script done).
Can someone please help me with #2?!!!! I would also prefer that it ignore any "RE:" or "FW:" prefixes and just copy the rest of the subject.
Thanks!
Hotkey to copy subject of email in Outlook
- coder_chick
- Posts: 235
- Joined: 05 Nov 2015, 10:43
Hotkey to copy subject of email in Outlook
♥ ❤ ❥ coder_chick ♥ ❤ ❥
- coder_chick
- Posts: 235
- Joined: 05 Nov 2015, 10:43
Re: Hotkey to copy subject of email in Outlook
♥ ❤ ❥ coder_chick ♥ ❤ ❥
Re: Hotkey to copy subject of email in Outlook
Maybe:I hope this helps
Code: Select all
; Get the subject of the active item in Outlook. Works in both the main window and
; if the email is open in its own window.
olApp := ComObjActive("Outlook.Application")
olNamespace := olApp.GetNamespace("MAPI")
; Get the active window so we can determine if an Explorer or Inspector window is active.
Window := olApp.ActiveWindow
if (Window.Class = 34) { ; 34 = An Explorer object. (The Outlook main window)
Selection := Window.Selection
if (Selection.Count > 0)
Clipboard := Selection.Item(1).Subject
}
else if (Window.Class = 35) ; 35 = An Inspector object. (The email is open in its own window)
Clipboard := Window.CurrentItem.Subject
MsgBox, % Clipboard
return
- AlphaBravo
- Posts: 586
- Joined: 29 Sep 2013, 22:59
Re: Hotkey to copy subject of email in Outlook
this also works to get subject, not sure how to set search
Code: Select all
oApp := ComObjActive("Outlook.Application") ; Get Outlook
oExp := oApp.ActiveExplorer ; Get the ActiveExplorer.
oSel := oExp.Selection ; Get the selection.
oItem := oSel.Item(1) ; Get a selected item.
MsgBox % Subject := oItem.subject ; Display subject
- coder_chick
- Posts: 235
- Joined: 05 Nov 2015, 10:43
Re: Hotkey to copy subject of email in Outlook
I am getting an error with that code. Any thoughts?
♥ ❤ ❥ coder_chick ♥ ❤ ❥
Re: Hotkey to copy subject of email in Outlook
Do you have Outlook open?coder_chick wrote:I am getting an error with that code. Any thoughts?
- coder_chick
- Posts: 235
- Joined: 05 Nov 2015, 10:43
Re: Hotkey to copy subject of email in Outlook
It seems to be working now. Maybe I had an old script running that was messing with it. However, what is the variable for the subject? If I want to paste it (using the Send,%subject%), how would i do that?
♥ ❤ ❥ coder_chick ♥ ❤ ❥
Re: Hotkey to copy subject of email in Outlook
In AlphaBravo's code, this line displays a MsgBox and stores the subject in the "Subject" variable at the same time:
MsgBox % Subject := oItem.subject ; Display subject
To Send instead of displaying the MsgBox, try replacing it with something like this:
MsgBox % Subject := oItem.subject ; Display subject
To Send instead of displaying the MsgBox, try replacing it with something like this:
Code: Select all
Subject := oItem.subject
SendInput, {Raw}%Subject%
- coder_chick
- Posts: 235
- Joined: 05 Nov 2015, 10:43
Re: Hotkey to copy subject of email in Outlook
It is not working now. I'm getting the same error as before. Is it working on your end? And yes, outlook is open. Running Outlook Professional Plus 2013.
♥ ❤ ❥ coder_chick ♥ ❤ ❥
Re: Hotkey to copy subject of email in Outlook
Yes it works for me in Outlook 2010.
Another way to get that error is if Outlook has been newly launched similar to what is described here. You can test if this is the case by temporarily activating a window in another application, then switch back to Outlook and test if your hotkey works.
Another way to get that error is if Outlook has been newly launched similar to what is described here. You can test if this is the case by temporarily activating a window in another application, then switch back to Outlook and test if your hotkey works.
- coder_chick
- Posts: 235
- Joined: 05 Nov 2015, 10:43
Re: Hotkey to copy subject of email in Outlook
Kon, thanks for the reply. I'm sorry. I'm a little bit of a n00b. Just a chick trying to learn all this coding stuff. Can you help me with some code that will perform that activating window test?
♥ ❤ ❥ coder_chick ♥ ❤ ❥
Re: Hotkey to copy subject of email in Outlook
Does the error occur only when you have just launched Outlook?
Does the error not occur if you minimize outlook, switch to another program, then switch back to outlook?
If you answered no to either of those questions then the problem you are experiencing is not what I am describing.
Hopefully someone else can offer more ideas regarding the cause of your error. Sorry, I'm out of ideas for now.
Does the error not occur if you minimize outlook, switch to another program, then switch back to outlook?
If you answered no to either of those questions then the problem you are experiencing is not what I am describing.
Hopefully someone else can offer more ideas regarding the cause of your error. Sorry, I'm out of ideas for now.
- coder_chick
- Posts: 235
- Joined: 05 Nov 2015, 10:43
Re: Hotkey to copy subject of email in Outlook
Error seems to always appear in both instances.
♥ ❤ ❥ coder_chick ♥ ❤ ❥
Re: Hotkey to copy subject of email in Outlook
Are you running AutoHotkey as administrator?
- coder_chick
- Posts: 235
- Joined: 05 Nov 2015, 10:43
- coder_chick
- Posts: 235
- Joined: 05 Nov 2015, 10:43
Re: Hotkey to copy subject of email in Outlook
Ok, I think I may have figured out the issue. Sinkfaze got me thinking. First off, it was not working when I ran it through SciTE4AutoHotkey. I needed to compile it. Then, once compiled, it did not work when ran as admin, but ran fine when not as admin.
♥ ❤ ❥ coder_chick ♥ ❤ ❥
- coder_chick
- Posts: 235
- Joined: 05 Nov 2015, 10:43
Re: Hotkey to copy subject of email in Outlook
Ok, now we are on to something. The code is now working. Just needed to compile and not run as admin.
Next step, adding some logic that if the subject starts with RE: or FW: to trim that off before sending the subject to the search bar. Any thoughts on this?
Code: Select all
F1::
oApp := ComObjActive("Outlook.Application") ; Get Outlook
oExp := oApp.ActiveExplorer ; Get the ActiveExplorer.
oSel := oExp.Selection ; Get the selection.
oItem := oSel.Item(1) ; Get a selected item.
Subject := oItem.subject
Send,^e ;shortcut to jump to search bar in Outlook
SendInput,"{Raw}%Subject%" ;sends subject to search bar in quotes
return
♥ ❤ ❥ coder_chick ♥ ❤ ❥
Re: Hotkey to copy subject of email in Outlook
Code: Select all
F1::
oApp := ComObjActive("Outlook.Application") ; Get Outlook
oExp := oApp.ActiveExplorer ; Get the ActiveExplorer.
oSel := oExp.Selection ; Get the selection.
oItem := oSel.Item(1) ; Get a selected item.
Subject := RegExReplace(oItem.subject,"^(?:RE|FW): ")
Send,^e ;shortcut to jump to search bar in Outlook
SendInput,"{Raw}%Subject%" ;sends subject to search bar in quotes
return
Re: Hotkey to copy subject of email in Outlook
Yes, you could use Regexreplace or Stringreplace.
- MasterFocus
- Posts: 146
- Joined: 01 Oct 2013, 09:47
- Location: Rio de Janeiro - RJ - Brasil
- Contact:
Re: Hotkey to copy subject of email in Outlook
sinkfaze gave you a fancy way of dealing with the prefixes, using RegEx.
Still, this could be easily implemented with things like InStr() and SubStr() (built-in functions).
I suggest you take a look at the documentation so you can do these minor tweaks by yourself.
(also, please avoid posting many consecutive posts so quickly - you can probably edit your last post if it's still "fresh" )
Still, this could be easily implemented with things like InStr() and SubStr() (built-in functions).
I suggest you take a look at the documentation so you can do these minor tweaks by yourself.
(also, please avoid posting many consecutive posts so quickly - you can probably edit your last post if it's still "fresh" )
Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.
Need help? Please post on the forum before sending me a PM.
Who is online
Users browsing this forum: Google [Bot] and 287 guests