Import Macros (*.bas File From Word For Mac
VBA for Mac Word vs. Word for Windows. While not a design issue, another missing feature on the Mac is the ability to directly export and import items in the Visual Basic Editor. If you have a.bas file from a Windows machine, you can use ‘File’ on the ‘Insert’ menu to add its contents to a module, but you cannot directly export. I assume that in your old personal file there are macros in one or more modules? I suggest that right click on each module in the file and export to a bas file. Do this for each module. Export the modules in your old file to bas files and then import them in the new personal.xlsb that you create. Macros and VBA tools can be found on the Developer tab, which is hidden by default, so the first step is to enable it. For Windows, go to File > Options > Customize Ribbon. For Mac, go to Excel > Preferences. >Technisat bda drivers for mac os. Ribbon & Toolbar.
Hi Robert What error message are you getting on the line you had to comment out? It would help a lot to have that information. I'm going to toss in some ideas here as I don't have time to do extensive testing on a part of the object model I don't use very often: 1. Are you sure you have to OPEN Normal.dotm in order to import that bas file?
NormalTemplate is available in the IDE without having to open it explicitly. Then you could try: wd.NormalTemplate.Save 2. If it turns out you do have to open Normal note that it's not 100% certain that ActiveDocument is the document you think! Much better is to declare and initiate an object for the document you're opening and want to work with: Dim nT as Word.Document = wd.NormalTemplate.OpenAsDocument Then use nT instead of ActiveDocument 3. Looking at the code samples for OpenAsDocument in the Help it gives the impression that you'd need to save changes to a new file name. In a way, this could make sense as Normal.dotm is in use.
If it turns out to be the case, save to a different name, exit Word, rename Normal.dotm to something else then rename the changed file to Normal.dotm and start Word again. Normal.dotm is already trusted by default, so you shouldn't have to worry about that. IT or the user could 'untrust' it, but a user will seldom do that and if it's IT you have someone to talk to. Your new question has received a reply in the separate thread.
Cindy Meister, VSTO/Word MVP. Cindy, After rewriting some code based on your suggestions, the only problem I seemED to still be having is illustrated by the error I get when I run the procedure below. HOWEVER, I have not located the problem which prevented me from saving the Normal Template - it was something in my own program, wherein I create an object to represent Word. Before trying to save or overwrite the Normal template, I 'quit' word, but simply with 'wd.Quit.' I forget to dispose of the word object properly, by calling a special routine I have created called 'StopWord'. Once I did that, everything worked fine. I'm leaving the routine below in there just in case you had already started looking at it.
But you don't have to look any further. Thank you again! Private Sub mnuDocFieldsImportFavListItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuDocFieldsImportFavList.ItemClick Dim WasWord As Boolean = IsWord If Not IsWord Then StartWord Dim Full$ = MacroDir$ & ' ' & 'FavList.bas' If Not IO.File.Exists(Full$) Then MsgBoxer('Can't find FavList.bas') Exit Sub End If Dim m$ = 'You must temporarily enable trusting Macros n (in FileOptionsTrust CenterTrust Center SettingsMacro settings) ' & 'first before continuing. ' & vbcrlf & vbcrlf & 'If you haven't done that yet, do it now. When you HAVE done that' & vbCrLf & vbCrLf & vbTab & '-Continue?' It works (I think).
Now I have to learn how to 'trust' the Word template I'm inserting the code into. Once I fix that, I'll know for sure. Hi Robert Glad Paul was able to give you the code you needed for this approach. If you could take a moment to close the other discussion by marking 'Answer' it will help forum admin:-) Trusting a template: The 'Trust Center' in the Options will give you an idea of the possibilities, but in a nutshell: 1. A digital signature for coding 2. Copying it to a trusted folder In both cases, the user (or IT admin) will need to trust the signature / trust the target folder (if it's not already trusted). If this is something that should 'always be available' then a good place to put it would be the 'Startup' folder so that it's always loaded when Word starts.
Import Macros (*.bas File From Word For Mac)
Cindy Meister, VSTO/Word MVP. Hi Robert If you're importing from a BAS file there won't be any warnings, etc. At that point. The 'security' question will only be about the code you're using to do the importing! A note about that: There's a special trust option that must be activated in the user's profile in order for code that manipulates the VBA environment to execute.
Installation default is OFF - it's a major security issue. File/OPtions/Trust Center/Trust Center Settings/Macro settings: 'Trust access to the VBA object model' The other question is what file format the template is into which you're inserting the code: it must be.dotm in order to hold a macro, meaning you might need a 'Save As'. If the template was not a dotm THEN where it's saved becomes critical. At this point, it needs to be in a 'trusted' location. A digital signature is not necessary (unless the client wants one), but your code can't add that to the template into which it's importing VBA code, anyway. If digital signature is wanted, the client can generate a private one, using a tool provided with Office, then use it to sign 'his' template in the VBA Editor (Tools menu). I know I'm not going into a lot of detail, here.
I don't completely understand your scenario and don't want to confuse the issue. Cindy Meister, VSTO/Word MVP. Cindy: You sure know Word! Thanks so much for all of your input. To keep things as simple as possible, my plan is to have my program notify the User when he/she runs the code to import the.BAS file, explain that he is the one who must allow macros to run in the Trust Center. (I can get my code to automatically display the Trust Center dialog necessary, if the User answers 'Yes' to the question of whether he will permit the import.) I can handle all that. Where I'm stuck right now is at the point where the template with the code imported into it must be saved.
The template I'm importing the.BAS file into is the User's Normal template ('Normal.dotm', I think), and before importing the code (assuming the User has agreed to the import and has also entered the correct info in the Trust Center), my code opens the Normal Template. My program then imports the macro (i.e., the.BAS file) needed to create the new List object, and then runs the macro, thereby creating the new List. All that works fine. But my code can't save the Normal template with the imported List in it. Here's my code: Dim Full$ = c: macros FavList.bas Try wd.NormalTemplate.OpenAsDocument wd.ActiveDocument.VBProject.VBComponents.Import(Full$) ' wd.ActiveDocument.Save wd.Run('FavList') Catch ex As Exception MsgBoxer(ex.Message) End Try I had to 'comment out' the line that saves the Normal template, because it won't execute.
So my first question is: how to get the Normal Template saved. When I used to use vb 6.0, I don't recall ever having this problem; if I opened Normal.dot 'as a document', I could later save it without worring about the file being a 'readonly' file or needing to make its folder 'trusted'. Trying to accomplish all that with vb.net now just seems to be pushing the limit for me and any users I can convince to use my program! Is there some way around this problem without having to instruct the User to make the Normal template's folder 'trusted' (assuming I can even figure out how to do that myself)?
Assuming I can get Normal.dotm saved, my next problem is going to be this - how do I get the new list (also called 'FavList') to be the default ListNum format? I already know that's going to be a problem, since I can even now try to do that in my code, even though I haven't yet saved Normal.dotm - the template DOES, at least temporarily, have the new list, and at this point I can't get that new list to be activated when the User is ready to enter a new ListNum.
Robert Homes. Hi Robert What error message are you getting on the line you had to comment out? It would help a lot to have that information. I'm going to toss in some ideas here as I don't have time to do extensive testing on a part of the object model I don't use very often: 1. Are you sure you have to OPEN Normal.dotm in order to import that bas file? NormalTemplate is available in the IDE without having to open it explicitly.
Then you could try: wd.NormalTemplate.Save 2. If it turns out you do have to open Normal note that it's not 100% certain that ActiveDocument is the document you think!
Much better is to declare and initiate an object for the document you're opening and want to work with: Dim nT as Word.Document = wd.NormalTemplate.OpenAsDocument Then use nT instead of ActiveDocument 3. Looking at the code samples for OpenAsDocument in the Help it gives the impression that you'd need to save changes to a new file name. In a way, this could make sense as Normal.dotm is in use.
If it turns out to be the case, save to a different name, exit Word, rename Normal.dotm to something else then rename the changed file to Normal.dotm and start Word again. Normal.dotm is already trusted by default, so you shouldn't have to worry about that. IT or the user could 'untrust' it, but a user will seldom do that and if it's IT you have someone to talk to. Your new question has received a reply in the separate thread. Cindy Meister, VSTO/Word MVP. The error message I get when trying to save Normal.dotm is that is is a 'readonly' file.
If I don't open Normal template, then when I import the.BAS file and then run it, wouldn't that put the 'FavList' style into a regular document or at least another template? If so, and if it's not going into the Normal template, then it wouldn't be available to the user all the time - right??
I'll certainly try your suggestion regarding using an object next! Could I do all that to the User's computer in my program code? Robert Homes. As long as you're targeting the Normal.dotm template, the macro module (the bas file you import) will reside in Normal.dotm and the macro will always be available to the user. Which document the macro affects will depend on the code IN THE BAS file. What you do to import the code has no influence on where the macro, itself, runs. Word.NormalTemplate.VBProject.VBComponents.Import Word accepts the above code line (although I didn't run it as I have nothing to import and have to shut down in about 10 minutes for the night) - and I have not opened Normal.dotm as a document.
Import Macros (*.bas File From Word For Mac Download
(BTW the error message confirms that there's a conflict between Normal.dotm being opened and at the same time being loaded as a template add-in.) 3. As long as your code is running outside the Word application, yes. Assuming it has the necessary permissions to change file names in the folder where Normal.dotm is located.
Cindy Meister, VSTO/Word MVP. Cindy, After rewriting some code based on your suggestions, the only problem I seemED to still be having is illustrated by the error I get when I run the procedure below. HOWEVER, I have not located the problem which prevented me from saving the Normal Template - it was something in my own program, wherein I create an object to represent Word. Before trying to save or overwrite the Normal template, I 'quit' word, but simply with 'wd.Quit.' I forget to dispose of the word object properly, by calling a special routine I have created called 'StopWord'. Once I did that, everything worked fine. I'm leaving the routine below in there just in case you had already started looking at it.
But you don't have to look any further. Thank you again! Private Sub mnuDocFieldsImportFavListItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuDocFieldsImportFavList.ItemClick Dim WasWord As Boolean = IsWord If Not IsWord Then StartWord Dim Full$ = MacroDir$ & ' ' & 'FavList.bas' If Not IO.File.Exists(Full$) Then MsgBoxer('Can't find FavList.bas') Exit Sub End If Dim m$ = 'You must temporarily enable trusting Macros n (in FileOptionsTrust CenterTrust Center SettingsMacro settings) ' & 'first before continuing. ' & vbcrlf & vbcrlf & 'If you haven't done that yet, do it now. When you HAVE done that' & vbCrLf & vbCrLf & vbTab & '-Continue?'