There seem to be many descriptions online about attachments with duplicate names. When you have a lot of attachments, it's not practical to manually save each one to a different name. It's also prone to manual error.
There are many code snippets for automating the saving of attachments, but I hunted for through quite few and experimented with VBA code snippets before assembling a complete subroutine. Hoping that my answer posted below will save someone an afternoon.
Here is VBA code that does what is needed:
Public Sub svAttachByIndx(Folder As String)
Set fso = CreateObject("Scripting.FileSystemObject")
For Each Atchmt In Application.ActiveExplorer.Selection(1).Attachments
FilePath = Folder & "\" & Format(Atchmt.Index, "00.") & _
fso.GetExtensionName(Atchmt.FileName)
Debug.Print FilePath
Atchmt.SaveAsFile FilePath
Next
End Sub
The VBA editor is opened from Outlook using Alt+F11. To use the above subroutine, select the message containing the attachments of interest, open the Immediate Window in the VBA editor (Ctrl+G), and enter:
Call svAttachByIndx("C:\User\Your.User.Name\Path\to\desired\folder")
Related
I am looking for some help getting an apple script setup. I have been trying to copy and past from different examples on the web to no avail. I am setting up a journal / diary for a family member and need to have a text file that contains the following information.
The AppleScript will display a dialogue box asking for three things:
The name of an event
The date of the event
A description for the event
Each of those would be stored as a separate variable.
Then the script would ask for a selection of files from the Finder, nothing nested, just a selection of 15 - 30 files all contained in the same folder.
Finally a new TextEdit document would be created
The beginning of the document would have the (3) variables mixed in with some default text.
The middle of the file would be filled in with a repeat loop based on the number of files selected from the finder. Their file paths would be mixed in with additional default text.
The last section would be default text only, no variables required.
I am sure my description is way more complicated than the script will probably be. Would anyone be able to provide this script for me? It would be most appreciated.
Here is a rough idea what the final thing would look like. The bold areas are the variables.
The activity of the day was scuba diving.
The date you went scuba diving was January 1, 2016.
This is a description of your event. The day was quite beautiful and the water was perfect. You were able to see a wide variety of fishes!
These are the locations of the files from this event.
The first file is /events/scuba/scuba1.txt
These are the locations of the files from this event.
The first file is /events/scuba/scuba2.txt
These are the locations of the files from this event.
The first file is /events/scuba/scuba3.txt
This was a summary of your scuba diving activity. These memories will last a lifetime!
I appreciate the help with this. And if the family member in question was able to provide a thanks, know that they would as well.
You can do that like this:
set evName to text returned of (display dialog "The name of an event" default answer "")
set evdate to text returned of (display dialog "The date of the event" default answer "")
set evDesc to text returned of (display dialog "A description for the event" default answer "")
set theText to "The activity of the day was " & evName & return & "The date you went " & evName & " was " & evdate & return & evDesc & return & return
set x to choose file with multiple selections allowed
set def1 to "These are the locations of the files from this event."
set def2 to "The first file is "
repeat with i in x
set theText to theText & def1 & return & def2 & (POSIX path of i) & return
end repeat
set theText to theText & return & "This was a summary of your " & evName & " activity. These memories will last a lifetime!"
tell application "TextEdit"
make new document with properties {text:theText}
activate
end tell
May I suggest an alternative solution using Evernote?
You could create a "template" note using a table to fill in the activity, date, and description. Any time you want a new journal entry, just select the template, and go to Note > Copy to Notebook.
Then you can attach and/or import the text of the files.
This would also allow you to add images and other attachments, and search much easier. And of course it is easy to share.
Let me know if you'd like more details.
Screenshot of example:
I am writing an add in for excel. It is supposed to create a new worksheet, then copy data from the pre-existing worksheets.
Now the whole add-in works on another excel document. But the one I need it to work in has disabled the ability to add new worksheets.
Can someone please tell me what code enables this?
Sub Auto_Open()
Dim WSheet As Worksheet
On Error Resume Next
Set WSheet = Sheets("DispersionList")
On Error Resume Next
Dim works As Worksheet
ActiveWorkbook.Unprotect
If WSheet Is Nothing Then
Set works = Worksheets.add(after:=Sheets(Worksheets.Count)).Name = "DispersionList"
Call makeFormat
Worksheets(1).Activate
End If
DispersionForm.Enabled = True
DispersionForm.Show
End Sub
Like pnuts mentioned above, if you search Google/SO, you will find plenty of posts which talk about hacking the password. However my answer is not about hacking the password but about alternative(s) that you can employ to play around with the workbook. If someone protected the Excel file then it is obvious that you are not meant to fiddle with it :) And as a personal choice, I do not assist with hacking. If you can get the password from the author then there's nothing like it.
There could be 2 kinds of protection that I can think of which will stop you from adding sheets to that workbook.
Via Code
Workbook Structure is protected.
If you want to play around with the workbook with not the intention of hacking it then you have couple of options.
If the protection is via code, then that file could be an xls or xlsm file which supports macros. Here what the author might have done is written a code where the moment you add a sheet, it is immediately deleted. In such a case, simply resave the file as an xlsx file. Close the file and re-open it so that you can then add sheets to it and play with it without hacking it.
If the workbook structure is protected then there is nothing much you can do except copy (if it allows) the cells from the existing workbook to a new workbook and then play with it
I have a word doc that I have been writing some VBA for, and in it I use this a lot:
LoadPicture(ThisDocument.Path & "image_name")
However, for this to work I've needed users to have an "Images" folder in the same directory, which is very inconvenient.
Is there a better way to include resources in a VBA project?
Thanks!
I use the QuickParts in Word to store them. Create a new document template, paste the image onto the page and select it. Then go to QuickParts and Add it to the Library and save your template. Repeat for each item to add. Then use VBA code to apply the template to the document and your QuickPart will pull in from the template. Then use a second macro to pull your image from the QuickPart.
Why not check if the folder exists on document open and create the folder if it does not?
Private Sub Document_Open()
Dim imagesFolder As String
imagesFolder = ThisDocument.Path & "\images\"
If Len(Dir(imagesFolder, vbDirectory)) = 0 Then MkDir imagesFolder
End Sub
I have thousands of html files, and need to save each of them as txt, using firefox.
If I do this job manually, I would open each html file in firefox, click the File menu, click the 'Save Page As' menu item, then select the format as 'TEXT', and save to local disk.
But how to automate this job?
Any script/tool can help this?
Thanks.
If your goal is to get firefox to strip the html out of each page and save just the text, then there are a ton of options. I'm not aware of any firefox add-ons that will be intelligent enough to loop over every file in a directory in order to perform a macro, so here are some options:
Refer to this SO question regarding how to use python to strip the html from each file. It provides examples for both the built in HTMLParser module and for using BeautifulSoup
Use Selenium to automate your webbrowser: http://seleniumhq.org/
If you know javascript, you can use PhantomJS:
http://www.phantomjs.org/, which is a headless web browser that you
drive with javascript scripts.
I have thousands of html files...
Do you actually have these files on-hand, or are they online?
...and need to save each of them as txt...
Any text editor should be able to save the data within (i.e. why use FireFox), and I think a straight rename of .htm or .html to .txt. will work (at least on any Windows system). Or do you mean: save just the displayed text of the HTML file?
EDIT:
First, start off with this link, which has a good explanation of how to get started with shdocvw, which you will need to do this.
Once you have the reference set up, using the functions
Function GetNewIE() As SHDocVw.InternetExplorer
and
Function LoadWebPage(i_IE As SHDocVw.InternetExplorer, i_URL As String) As Boolean
from the link (just copy into your project as described in the link) to load your individual html files, using a loop to get through each file. (Excel would be good for this, because you can put your list of files into the cells, and cycle through each cell to retrieve.) I have never done something like this with so many files, so I cannot guarantee this will work, unfortunately...
Dim IE As SHDocVw.InternetExplorer
Dim lRow as Long 'Long in case you have a LOT of files
Dim iFNum As Integer
Dim sFilePath As String
Set IE = GetNewIE
For lRow = 1 To 5000 Step 1 ' Assuming you have 5,000 html files, so 5,000 rows with the paths to each
sFilePath = ActiveSheet.Range("A" & lRow).Value ' This should also include the filepath. i.e. "C:\dir\..."
If LoadWebPage(IE, sFilePath) Then
iFNum = FreeFile(lRow)
Open sFilePath & ".txt" For Output As iFNum
Write #iFNum, IE.Document.InnerText
Close #iFNum
End If
Next lRow
If I have a VBScript like...
inputControl1 = InputBox("Hello World")
WScript.Quit
How can a check box be created in there rather then the InputBox?
I know VBScript itself does not have a checkbox control like the InputBox, but is there some library I can use to do something like the following?
inputControl1 = CreateObject("library.checkboxcontrol")
WScript.Quit
Couldn't you use a yes/no msgbox instead?
dim Answer
Answer=msgbox("Your question here",4)
You could use an HTA. That would be more involved than a VBScript, but it would be written in VBScript + HTML. There would be a few IE restrictions you may have to work around though.
Alternatively if you get VB.NET Express and code using that. It is a different language of course.