I wrote a VBA script to send emails to an arbitrary number of contacts from an excel file. The excel file basically has a column of email address's and attachment's, where attachment's is the name of the file to attach to the email. What I want to do is be able to add multiple attachments, by separating each attachment by ; in the attachments column and making the script go on to add the next attachment. The trouble I am having is I don't know how to do it without setting a fixed number of attachments for contacts. The scenario I am trying to capture is, one contact can have 3 attachments, another one could have 2 and another 0 attachments.
You can split a text in a cell to an array, then just loop through the array.
Const DELIMITER = ";"
Dim strCellText as String, strAttachment as String
Dim strAttachments() As String
strCellText = 'load your cell text here
strAttachments = Split(strCellText, DELIMITER)
For Each strAttachment In strAttachments
'attach an attachment to a mail
Next
Related
I hope you can help me. I am new to Outlook 2010 VBA, but need a macro to :-
Save a group of highlighted e-mails :-
a) As .msg files;
b) In a given folder;
c) Where the name of each is the attachment name.
To give you an example, say there are 20 e-mails in my sent items folder, I want to highlight 10 of them and run this macro, winding-up with 10 flat files in a given folder which bear the name of the attachment for each e-mail.
Every e-mail subjected to this macro will have just one attachment, so to be crystal-clear, if we have an e-mail with a subject line "Random Text goes here doesn't matter what", and an attachment "GO.XLSX", I want the extracted file to be called GO.msg and, to confirm, this is Outlook 2010 I am running.
I have looked through loads of VBA sites and macro snippets, but I am getting nowhere =[
Not sure if I understand your problem, but here is a quick example:
Sub QuickExample()
For Each Item In Application.ActiveExplorer.Selection
If Item.Attachments.Count > 0 Then
Debug.Print Item.Attachments(1).DisplayName
End If
Next
End Sub
I have some excel workbooks of same header rows. I need to search in a particular column in all these workbooks and do a countif kind of functionality in a corresponding column( different than the first column)
For eg.. Column A has names of boxes, B has information about the contents in each box. I would like to search multiple excels in folder and get a report of unique box names and their content counts. Box A has 5 apples, 2 oranges , 1 mango.
I hope this requirement is clear enough. Could anyone help me with a base axcel macro code?
Talking about workbooks you have different files (*.xls) in one folder? Then you can start with something like this:
Dim Path As Integer
Path = "Type in the path with your workbooks"
File = Dir$(Path & "\*.xls")
Do While File <> ""
'Do stuff like:
'opening your workbook and search for the names of the boxes
'save your needed informations in a variable or array
'close the workbook
File = Dir$()
Loop
Or do you mean you have one workbook (one file) with more worksheets? Then do something like this:
Dim i
For i = 1 To ThisWorkbook.Worksheets.Count
'Do your stuff here
Next i
If you want to get better help please post some of your code with specific questions
I am trying to create a VBA script which will read Text Files which I have converted from PDF Files and pull out key information following search words. All the Text Files will be located in a central location C:Work\Text
Within each of these Text Files is information that I would like to pull out and put into columns within Excel. The search word helps identify the information but the search word may be different in each of the Text Files, so I will need to create a Table of search words. And once it finds the information in one text file it can move onto the next one it doesn't need to post every instance of the search word appearing in the text file.
Example:
I am looking for Account Numbers and Amounts
Text File 1: Account Number can be found within the text file by Searching the word "Account Number:" and Amount can be found by searching "Amount:"
Account Number: 1234
Amount: $10
Text File 2: Account Number can be found within the text file by Searching the word "Account" and Amount can be found by searching "Cost"
Account 00090
Cost 25
Text File 3: Account Number can be found within the text file by Searching the word "Initial Number" and Amount can be found by searching "Total"
Initial Number 555555555
Total $90.02
Etc
So essential I would want to create a mapping table that references these Search Words and for it to just bring in the information after the search word . If a new search word needs to be added I could always just add to the mapping table.
The output would essential put All the Account Number data into Column A1 and all the Amount Data will go into B1
I wrote sample code to give pointers. You may need to iterate the same piece for rest. You may add multiple if conditions to search for the other patterns(just a suggestion)
Const ForReading = 1
Dim strSearchFor
dim i=1
Set objExcel = CreateObject("Excel.Application")
‘Set objWorkbook = objExcel.Workbooks.Open("C:\test.xls")
objExcel.Application.Visible = True
objExcel.Workbooks.Add
For Each f In objFSO.GetFolder("C:\some\folder").Files
Set objFile = f.OpenAsTextStream
strSearchFor = "Account Number"
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
'do stuff with strLine and append to strText
If InStr(strLine, strSearchFor) <> 0 then
Wscript.Echo "Account Number found"
objExcel.Cells(i, 1).Value = strLine
i=i+1
Else
Wscript.Echo "Account Number not found"
End If
Loop
objFile.Close
Next
objExcel.ActiveWorkbook.SaveAs "C:\test.xls"
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
I have a three worddokuments. The first hast the following structure:
Text
Hyperlink
Text
Hyperlink
I try to accomplish the following marcro: Open document 1, loop throu the hyperlinks. Open the hyperlinked documents and insert the text in the documents where the hyperlink in document 1 is.
What I accomplished yet is
Dim hLink As Hyperlink
Dim doc As Document
'Loop throu all hyperlinks
For Each hLink In ThisDocument.Hyperlinks
'Set objectref to document behind hyperlink
Set doc = Documents.Open(hLink.Address)
'AAAAnd Close it.
doc.Close
Next
My problem is, that I do not know how to put the text of the open document, where the hyperlink is and delete this hyperlink. For further puproses the document 1 has to be flexible so that the user can insert hyperlinks and the functionality of inserting is still working.
I thought of deleting the hyperlink and place a bookmark at the same position, name the bookmark, insert the text and delete the bookmark afterwards, but I do not get the hyperlink replaced by a bookmark. I found the hyperlink.Range.Bookmarks Property but no way to use it for my purposes. Anyone who can help me get this done?
Dim i As Long
For i = ThisDocument.Hyperlinks.Count To 1 Step -1
Dim link As Hyperlink, r As Range, addr As String
Set link = ThisDocument.Hyperlinks(i)
Set r = link.Range
addr = link.Address
link.Delete
r.InsertFile addr
Next
What I have is an excel spreadsheet with hyperlinks to documents online, I want to print a certain range of these depending on requirements. Most of the time the whole document needs printed, but sometimes we only want certain pages printed, ideally this range of pages would be printed stapled as well.
I have a macro that somewhat does what I'm after:
Option Explicit
Sub PrintHyperlinkedPDFs()
Dim PDFrng As Range, PDF As Range
Dim AdobeReader As String, pdfLINK As String
'there is an extra space at the end of this string
AdobeReader = "C:\Program Files\Adobe\Reader 11.0\Reader\AcroRd32.exe "
Set PDFrng = Selection 'change this to whatever method you want for setting
'the range of PDF link cells to process and print
For Each PDF In PDFrng
If PDF.Hyperlinks.Count > 0 Then pdfLINK = PDF.Hyperlinks(1).Address
Shell """" & AdobeReader & """/n /t """ & pdfLINK & """"
Next PDF
End Sub
You highlight what cells containing the links you want to print then run and it sends some of them (if its more than around 4 documents it freezes and doesn't send them all).
Ideally, I would like to set-up some buttons to print pre-defined combinations of these documents but I'm not exactly a VBA professional and therefore this may be out of my skill range..
Any help would be much appreciated.
You can add a Button directly on the Sheet and assign the macro SetupBtn already stored in the sheet:
Sub SetupBtn()
ActiveSheet.Range("B2,B4").Select
PrintHyperlinkedPDFs
End Sub
This macro use your Sub, selecting the cells you want before the Sub.
Creating the combination of cells, you create combination of print.
The sequence of cells are the sequence of print. If you want two copy of a document (for example a separator of pages), write something like that:
ActiveSheet.Range("B2,B4,B2").Select
It's strange, but print 3 doc with 2 cells selected...