Outlook vba to create folder and file emails based on subject phrase - vba

I found this create an outlook rule to create folders if needed based on text in subject line
Which gets me 99% of the way there. But I would like the reference point to create the folder name to start after a set character. For example if the subjet was "xxxx #1234", I want the folder name to be 1234, not #1234 as would happen if I put the str value as #. Any pointers?

It looks like you need to get a substring, see String Manipulation
for more information about string VBA functions.
For example, to get number you can use the Right function:
MsgBox Right("xxxx #1234", 4)

Related

Outlook VBA to search Email Subject for specific string format and copy to clipboard

I need to write a VBA that searches the subject of the highlighted EMail for a specific format of a string (is a reference number of a case).
The format is as follows:
3 capital letters / 1 or 2 numbers / 3 or 4 numbers / 2 numbers
e.g. ARK/5/1128/19 or RUB/11/548/19.
As soon as found to be copied into clipboard as this is a part of a longer procedure that needs to enter this ref no to a field.
This is part of a procedure that archives emails to public folders.
This code will assist to find the ref no easier and copy into clipboard so the user can paste it in the search box.
expect that string such as ABC/10/123/19 or DEF/4/1254/18 will be found and copied into cilpboard.
You can use regular expressions to evaluate the condition, whether the subject contains the string that corresponds to the pattern. Take a look at the following articles for more information on regular expressions:
VBA RegEx: How to Evaluate and Use “Regular Expressions”
How to use Regular Expressions (Regex) in Microsoft Excel both in-cell and loops

Get upercase within String Value

I am currently working on a tool to automatically send out emails.
Within this tool one variable is the pathway in which the attachment is to be found.
The file names are automatically generated within a folder, but sometimes got strange symbols and/or uppercase letters, like this: "Sⁿkwrld.xlsx".
By collecting this value within a string, VBA retrieves: "Snkwrld.xlsx". This results in not being able to find the right file.
Is there a way to fix this problem and let VBA retrieve the correct value with the uppercase "N"?
Thanks in advance!
Best Regards,
Remco Coppens

Turning a string of characters into a hyperlink

I have searched a ton for an answer to this question and I can't seem to find one that is specific to my needs. I think it might be possible that I am just not understanding how hyperlinks work in VBA.
Currently, I have an array of strings (each representing a separate file on my server), and I want to add a hyperlink to each string that will take it to the file location on my server. I want that string to be hyperlink-ed so when I paste it in to Word or Outlook, it will already be hyperlink-ed. In my mind, it seems like this should be a fairly straight-forward task; you have a string of text, you have a file location, and you want to hyperlink that string of text with the file location.
For example, let's say I have an array like below:
docArray = {"myDoc1", "myDoc2", "myDoc3"}
which contains the names as string of 3 documents.
I have another array with the file location of each doc:
docLocArray = {"C:\Documents\myDoc1.docx", "C:\Documents\myDoc2.docx",
"C:\Documents\myDoc3.docx"}
The pseudo-code for this would be something like:
Hyperlink.Add(docArray(1), docLocArray(2))
Is there any way I can do something like this, or am I completely misunderstanding how hyperlinks can be used?
I am working in Autodesk Inventor if that is of any relevance to anyone.
Try this in Word:
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="C:\Testdir\Testfile.txt", SubAddress:="", ScreenTip:="", TextToDisplay:="MyFile"
Then just loop through the arrays for the values of Path and Filename.

Microsoft Word VBA - IF & THEN Find word and print in another sheet

I am a bit of novice when it comes to VBA (mostly navigate through the code by Recording actions and then altering it accordingly to what I need).
My current problem is the following:
I am going to compile hundreds of word Docs that contain email addresses from clients that I need. In order to make this as easy as possible, I would like to have some code that finds their emails AND additional information that surrounds the email addresses (Name, Location,Job Title,and [possibly] Phone Number) and then copies and pastes the mentioned info to another designated document. The documents and the abovementioned info are formatted as such :
FirstName LastName
Location
Job title # Company
email address - phone number
Now, I believe this will include and IF/THEN statement since not all clients have their email addresses in the documents.
So, IF there is an email address THEN copy it along with the 3 lines above and the phone number that is separated by "a space" "-" "a space"AND paste it on another sheet. IF there is no email address, then keep going.
This query code will probably include a FIND that needs to have a "#" and ".com" attached to the same string. This will be needed since the document also includes other text that has ".com" and "#" but not together.
This sounds harder than what it really is, but again I'm a novice so not completely sure. Feel free to ask any additional questions!
This is an extremely broad question, but I suggest you do the following:
Use a Scripting.FileSystemObject to iterate through files in a folder, looking for Word documents
Open the document using the Word Automation object model
Application object
Application.Documents property, and Documents collection
Documents.Add method, and the Document object, to create the destination document
Documents.Open method, to open existing documents
Find emails within the document (via the Document.Content property, and the Range object)
Range.Find property and the Find object
If the Find.Execute2007 method returns true, then:
Extend the range to the previous 3 paragraphs
Range.MoveStart method
Copy and paste the range to the destination document
You can write only the text to the destination document — Range.Text property, and the Range.Insert-* methods
Or, you can use the clipboard Range.Copy and Range.Paste
Or, you can export to an external file (Range.ExportFragment) and later import from the external file (Range.ImportFragment)

VBA Macro to extract strings from word doc

i have a word document containing several strings. These strings have the first part always the same, for example ABC_001, ABC_002, ABC_003. I need to search for "ABC_" substring in the doc, extract all the occurences ("ABC_001", "ABC_002", "ABC_003") and copy them in an Excel sheet.
Anyone can help?
Thanks in advance.
You can reference the VBScript Regular Expressions 5.5 and regex them.
Have a look at http://www.macrostash.com/2011/10/08/simple-regular-expression-tutorial-for-excel-vba/
and http://txt2re.com/
and some of VBA multiple matches within one string using regular expressions execute method
EDIT:
Actually it is probably easier to go to data and "Get external data" choose de-limiter and import, either manually or record a macro to get a feeling for the vba structure.
This should get you all the entrys in seperate cells, then go over them with a MID to get the part you need