Attaching a file with a worksheet to be emailed - vba

Just to give you a bit of a background, I am an IT contractor. I was looking for an accountancy package that I could use to do my day to day accounting. After searching for nearly 2 weeks, I was not happy with anything out there. So I've decided to build my own on Excel. I have listed requirements to that end. One of my requirements for the package is to be able to attach files with my workbook so that I can then send them to my accountant. Attachments will be invoices, receipts, expenses etc. My question is, is there a way to attach files with workbook that I can then email with the workbook? I know I can attach files within a workbook but that uses local UNC path and that wont work when I email the workbook. I am not using outlook so that is not something I can tap into. Any suggestions would be greatly appreciated

Click where you want to embed a file and go to the Insert ribbon. Then choose Object, followed by Create from file, and browse to the file. This should 'attach' the file rather than just linking to it.

Related

To have a Bat file see if the document is open, before opening the document again, but still executing the bat file

I have a word document with around a hundred bookmarks, each with a Macro programmed in for each Bookmark.
I created a word macro for each bookmark:
Sub Coronado()
Application.ActiveDocument.Bookmarks("Coronado").Select
End Sub
And then created a bat file to take me to the bookmark I need to go to:
"C:\Program Files (x86)\Microsoft Office\Office12\winword.exe" ""C:\Users\1241\Desktop\WorkFiles\HotelDel.docm"" /mCoronado
My new question is:
Is there a way to run this bat file, so that if the document is already open, it will just run the macro without reopening the document again.
I have several of these macros and bat files I am using, and would like the bat files to go to the macros in the word document without reopening the word document each time. After a while I would have numerous instances of the word document open, and then have to close them all.
OK, I have decided to go with VB Scripts, It has been a much easier process.
What I am doing is using a programmed voice software to activate scripts.
While I am talking to the customer, I say the name of the Word document, and then my voice command brings up the word document. As the customer asks questions, then I say the name of the question, and the voice command I have programmed in uses a VB Script to automatically go to that bookmark where the information I am trying to find for the customer is. This way I cut down on a lot of time searching through this word document fort the information the customer is looking for. This is all done with voice activated commands, such as "Parking Policy" or "Pet Policy". When I say these words, the computer automatically takes me to that bookmark in the document with no typing involved.
The issue I am having now, Is how to program a global Variable for each document I bring up. I need all previous variables cleared, and then I need the new variable put in place. For instance I say the name "Hotel Del Coronado" and that information document is brought forward on the screen. I need the path of that document to become the new variable for Hotel. Now when I say the name of the bookmark, it uses the path of the current document to go to that bookmark in the current document. This way I only have to program the Bookmark Scripts once. Each of my documents have the same bookmarks. So if I have the Variable Hotel set for the new document, Then all of the bookmark commands will be set for the new document.

Excel and Sharepoint integration

I can't really find a clear answer or solution for my problem.
What I have is the following: An excel file where a user inputs data in a UserForm and that data is then added to a table in this same excel file. Multiple users will get such an excel file so that they can add data on their own.
What I want to do is to aggregate this data in my own Excel file. Or Sharepoint List. I don't really prefer any option as both would work for me.
The user excel file is done and works. All that is left to do is to send the data in the table to a sharepoint list by clicking a button on the excel file.
I am able to import the excel data to sharepoint just fine, but I want the user to be able to "upload" the data to sharepoint by clicking a button. I did find code for that but it appears to be outdated as some functions are not used in Sharepoint anymore.
Does anyone have a solution or an idea how I can create a button in my excel sheet to send the data from several excel files (each with their own button) to a singular sharepoint/excel file (which would be my file).
I have been looking for days and tried powerapps, sql, acces and other approaches but none worked as they should.
Thanks!

Excel 2016 vba editor, cannot open ThisWorkbook module

I have an Excel 2016 file (.xlsm). After few weeks working on this file, now I'm facing with one small but weird problem - cannot open ThisWorkbook module. As you can seen in the picture, trying to open this module, window just simply freezes on the screen, any mouse's single or double-clicks on it have no effect.
Maybe somebody also had the same issue? What might cause it and how to resolve it?
this might have only worked for me but is worth a try
clear the office cache (C:\Users\username\AppData\Local\Microsoft\Office\16.0\OfficeFileCache\0)
open the file on a different computer and name it something random.
open the file on the first computer and resave file.
As pointed out in Han's comment, it's possible that the module is corrupted. You may be able to salvage it by right clicking the module and using 'Export File...' to save it as a class file.
If this succeeds you can attempt to recover your code by:
Importing the saved file, this will add 'ThisWorkbook' as a class file that can be opened like other modules.
If this doesn't work, try opening the saved file in Notepad. This should reveal your code in plain text.
I literally have this probablem every day or so. There is no answer, I have to save multiple files everytime I make any changes to the workbook. Its incredibly frustrating when all the macros disapear from the list and you can't open a single module

separate files for VB code and Excel

I'm using Excel 2010. I have some code in background (VBA) that is growing up from time to time. I'm trying to find a way to separate the source code from the xls file, so I could compare the code changes. In other words, I want that the code will be in a textual file, and every time I'll open the Excel file, the source code for macros will be taken from this file.
Thanks in advance!
Take a look at this question on SO.
It has the mention of addin called SourceTools, that I have used & find it worthwhile.
Also, it comes with source code so it can be modified to point it to the source code control software (such as SVN) that is specific to your use.
Feel free to close this question as the link I gave has the same question as yours & answers what I suppose you are looking for.
Have a look at the various code cleaner apps/code available for VBA, such as:
http://www.appspro.com/Utilities/CodeCleaner.htm
Among other things, these export the modules/forms/classes to text files, delete them, then re-insert them into your projects.
With a few mods, that'll form the basis for what you're after.
Another possibility: I don't do much in Excel, but if its add-ins behave like those in PowerPoint, that might help also. In PPT, installed add-ins load automatically when PowerPoint starts, create any user interface needed and are available to use with any open files in the app. To update the code, you modify it, create a new add-in, put it wherever PPT is looking for it, and restart PPT. Voila ... code's updated for all PPT files.
First of all, thank you all for your answers. my solution was:
1. export all the modules to *.bas (one file per module).
2. add the modules code my calling:
Application.VBE.ActiveVBProject.VBComponents.Import (filename)
for each file..
3. after finishing:
Set VBComp = VBProj.VBComponents(moduleName)
If Err.Number = 0 Then 'no error
VBProj.VBComponents.Remove VBComp
that's remove the module so it won't be saved in the xls before quiting
I would recommend a manual process in such a scenario.
Suppose you want to take a backup of Module1, then right click on it and click on "Export File". You will get an "Export File" dialog box. Save it as, say Module1 - 22 Apr - 2012.bas at a relevant location. And you are done
How would this help?
1) The dates in the file name will tell you what date the backup was taken so you can actually keep track of the date when the macro was changed.
2) .Bas files can be opened with Notepad. This will help you in comparing the current VBA code with the relevant backup file.
3) If at any point of time you want to retrieve the backup from a particular date, simply delete the existing module (take a backup of it if you want) and then click on "Import File" and import it in your VBA.
HTH

How to Create VBA Add-In with Shared Codes for All Excels?

I'm writing VBA codes for multiple Excel spreadsheets, which will be shared with others from time to time. At some point I find there are lots of duplications in my works. So I want to find a way to share codes in a sort of Excel add-in, like the .xla file.
But when I tried to save the Excel file containing shared codes as .xla file, I got some problems:
The file cannot be edit anymore after I save it in the default add-in folder
If I move the .xls file to a folder other than the add-in folder, and open it directly - I cannot use its classes - which creates problems for sharing the codes
Any ideas to create add-ins in a flexible and powerful way please?
Thanks a lot for the help
Not completely sure this is what you're looking for, but ...
(1) save the .xla/.xlam code by clicking the save icon in the VBA editor. HOWEVER, the thing that saves is the thing currently selected in the Project Explorer pane, which lists all open VB Projects and which is usually on the left. Even if you are staring at your just-edited VBA code, clicking the save icon will not save your code unless it is also selected in the Project Explorer pane. You won't get feedback that anything was saved - but you can verify by checking the file timestamp in a separate window.
(2) if you have an *.xls file which (via the formula bar) refers to VBA functions from your *.xla / *.xlam file, then if you open the *.xls file without opening the .xla,.xlam file first, Excel may create external links to resolve the formulas (i.e. referring to a file which is not open). If you have moved or renamed the *.xla file you can get stuck with those "mangled formulas" and need to edit out the pathname links that Excel inserted using a global substitute. If you arrange to open the .xla,.xlam prior to any *.xls file that uses it, you shouldn't have a problem (e.g. by using the default folder).