I am using a VBA code to write an email in Outlook with the information from a PowerPoint file and saving it as a draft, in the format ".msg".
With OutMail
.To = name_email
'Add file likethis
.Attachments.Add ("C:... " & numb_slide & ".pptx")
.Subject = "... " & date_c & " | Open Tasks " & name_project & " | Feedback ... " & dead_line_date & ",..."
.Body = StrBody
'.SaveAs "C:... " & CStr(date_c) & " | ... " & CStr(name_project) & ".msg", 5
.SaveAs "C:..." & numb_slide & ".msg", 5
'.Display Or use .Send
End With
I have two problems:
1) When I save the file using:
.SaveAs "C:..." & numb_slide & ".msg", 5
The program does not give me an error but I cannot open the draft that was saved, the error states:
If I create a normal email and save it as a draft, I can open it later.
2) If I change the way I save the file, like:
.SaveAs "C:... " & CStr(date_c) & " | ... " & CStr(name_project) & ".msg", 5
Or
.SaveAs "C:... " & date_c & " | Open Tasks " & name_project & ".msg", 5
It gives me the following error before finishing the task:
The variables I am writing in the name are strings, but I also tried to write them using CStr() to check if it would make any difference, and it does not!
I think you want 3 instead of 5.
From the olSaveAsType enumeration:
3 corresponds to Outlook message format (.msg)
5 corresponds to HTML format (.html)
Alternately, you could just drop the file type. From the MailItem.SaveAs documentation,
If the file type is not specified, the MSG format (.msg) is used.
Related
I'd like to add a network file link to my email body using Excel VBA.
The code below add the text, but I'd like file location to be a hyperlink?
strbody_2 = "<BODY style=font-size:11pt;font-family:Calibri><b><u>" & "CapAd File:" & "</b><u>" & "<br>" _
& Sheets("Control").Range("CapAd_File") _ ' THIS IS THE FILE LOCATION
& "</b></u>"
try using the html <a>-Anchor tag:
strbody_2 = "<BODY style=font-size:11pt;font-family:Calibri><b><u>" & "CapAd File:" & "</b><u>" & "<br>" _
& "<a href=""" & Sheets("Control").Range("CapAd_File") & """>" _
& Sheets("Control").Range("CapAd_File") _ ' THIS IS THE FILE LOCATION
& "</a></b></u>"
(sorry if i didn't get the apostrophies correct i didn't test it before i posted)
So I will try and be as clear as possible.
I am trying to make a macro that will populate and email with the following things:
Values from Listboxes
Writing for the main message
and a Table of values (which I've currently got being populated as a HTML body.
For example, I would like the email body to look as follows:
"Dear" [Name from preselected listbox]
"In order that we compile the latest update for the NAV please can you arrange the following information to be provided for" [The date]
[LIST THROUGH HTML]
"Please can you provide this information by the folowinf date"/....
I've currently got the list being pulled through correctly, but that has then stopped the vba body being entered. Therefore, the following code only pulls through the list.
Dim Addressee As String, SenRan As Range ' Define the receipient as words
Addressee = Application.VLookup(SourceLiBo.Value, Sheet1.Range("A1:B1000"), 2, False) 'finds the email address for chosen name
Set SenRan = ThisWorkbook.Sheets("Assets").Range("A1").CurrentRegion 'Selects the range of assets to be emailed.
With OEmail
.To = Addressee 'Send to addressee
.Subject = "Information Request " & Format(Date, "mmmm")
.Body = "Dear " & Me.SourceLiBo & "," & Chr(10) & _
"In order that we can compile the latest update for the NAV, please can you arrange the following information to be provided for " & Format(Date, "mmmm") & ":" & Chr(10) & _
""
.HTMLBody = rangetoHTML(SenRan)
End With
How is the best way to go about this in order to have all the data pull through. I would set variables with the strings wanted for the body and input it through .HMTLBody, but would that also allow me to pull through th listbox values in HMTLBody
I have now reworded it, thanks to braX explaining my errors. The code below (with the Ron Bruin Function) provides the correct answer.
With OEmail
.To = Addressee 'Send to addressee
.Subject = "Information Request " & Format(Date, "mmmm")
.HTMLBody = "Dear " & Me.SourceLiBo & "," & _
"<br><br>" & _
"In order that we can compile the latest update for the NAV, please can you arrange the following information to be provided for " & Format(Date, "mmmm") & ":" & _
"<br><br>" & _
rangetoHTML(SenRan) & _
"<br><br>" & _
"Please let us know if there are any additional purchases not reflected in the list above." & _
"<br><br>" & _
"Please can you provide this information no later than 10 working days from the date of this email to allow us to process all updates for delivery." & _
"<br><br>" & _
"Many Thanks"
End With
Unable to SaveCopyAs to proper path using vba:
ThisWorkbook.SaveCopyAs Filename:=ThisWorkbook.Path & "Rounds " & Month(Sheet4.Cells(1, 2)) & " - " & Year(Sheet4.Cells(1, 2))
The code is saving just short of the file path. Folder is located on a folder on the desktop but the new file is being saved to the desktop.
Path returns the folder the workbook is saved under. Sounds like you want:
ThisWorkbook.SaveCopyAs Filename:=ThisWorkbook.Path & "\Rounds " & Month(Sheet4.Cells(1, 2)) & " - " & Year(Sheet4.Cells(1, 2))
If you run this:
Sub TestMe()
Debug.Print ThisWorkbook.Path
End Sub
you would see something like: C:\Users\Username\Desktop in the immediate window.
Thus, if you run your code like this:
Debug.Print ThisWorkbook.Path & "Rounds " & Month(Sheet4.Cells(1, 2))
You would most probably see something like this:
C:\Users\Username\DesktopRounds 12 and this is not what you need. There is obviously a / missing after the Desktop. Thus, put it there and try further:
ThisWorkbook.SaveCopyAs Filename:=ThisWorkbook.Path & "\Rounds " & Month(Sheet4.Cells(1, 2)) & " - " & Year(Sheet4.Cells(1, 2))
I have a report in which I allow multiple users to generate their specific version and then save the file but I do not want them to overwrite my master file.
So I created a save-as dialog that saves the file with a specific name (the parameters after .show property are just different parts of the file name).
But the dialog allows users to save the file in the same folder I have the master file by default and I would like to change this to by default offering Documents folder. Is there a way to change this?
Application.Dialogs(xlDialogSaveAs).Show FYandQName & " " & _
CountryName & " " & BusValue & " " & "Financial Narratives"
Try this:
Dim s As String
'assuming an .xlsx file
s = FYandQName & " " & CountryName & " " & BusValue & " " & "Financial Narratives.xlsx"
With Application.FileDialog(msoFileDialogSaveAs)
.InitialFileName = Environ$("USERPROFILE") & "\Documents\" & s
.Show
.Execute
End With
on my excel sheet the user can choose some video clips and arrange in different order to play as a vlc playlist. Unfortunately it can’t be guaranteed that the video file names haven’t any blanks.
To build the vlc playlist I use successfully:
Dim PL
PL = Shell("C:\Program Files\VideoLAN\VLC\VLC.exe " & certainPath & "\Movie6.flv" & " " & certainPath & "\Movie7.flv" & " " & certainPath & "\Movie8.flv ", 1)
'using "\Movie 6.flv" 'doesn't work of course
'using "\'Movie 6.flv'" 'doesn't work aswell
Is there another way to encapsulate file name with blanks?
thankfull for a hint.
Assuming that certainPath folder end with \ ( es. "C:\" ), this should work:
Dim PL
PL = Shell(chr(34) & "c:\Program Files\VideoLAN\VLC\vlc.exe " & chr(34) & chr(34) & certainPath & "Movie 6.flv" & chr(34) & " " & chr(34) & certainPath & "Movie 7.flv" & chr(34))
CHR is a function to returns the character from the ASCII table (the quotes in this case).