I'm working on a VBA macro which generates an Excel report out of a Microsoft Project planning.
In order to save the report, I have to open a Save File Dialog by calling
GetSaveAsFilename("name", , , "Title"), but I don't want to use the Excel.Application for this because I'm supposed to activate it first which doesn't make sense.
How should I call GetSaveAsFilename through the Microsoft Project application?
MS Project uses FileSaveAs instead of GetSaveAsFilename, which has several arguments. If you leave them blank you will just get the SaveAs dialog box.
Related
I'm trying to create my first Excel Add-In for Excel 2010. Most of it is working, it's running from the ribbon buttons, but I'm having trouble addressing the Add-In's subroutines from my workbook's VBA code.
According to this answer on SO, it should be possible to simply use the syntax:
mySub
or
Call mySub
But this causes the error "Sub or Function not defined". I've only managed to run them this way:
Run "mySub"
or
Application.Run("myAddIn.xlam!mySub")
Is there a way to include the Add-In so I can address it the easy way?
The Add-In is already checked in the Tools->Add-Ins list, and has a unique name (CalcFunctions) which is different from its file name (CalculationFunctions.xlam). The Add-In file is on a different disk and I'm working on a server, but I don't expect that that matters.
(Posted on behalf of the OP).
Turns out I'm just dumb. I only set a reference to the Add-In in the regular Excel window. I assumed that was what people meant by Tools->References->Add-Ins (I use Excel in Dutch and there's no "Tools" menu). Anyway, the solution was setting a reference in that menu in the VBA editor window.
Here's how to add a reference in VBA:
ThisWorkbook.VBProject.References.AddFromFile refPath
With refPath being the full path to the file.
To be able to add references you need to have permission to edit the VBA project. You can enable this in excel settings->trust center->macro settings. If you're on a company pc it's likely the administrator has to set these settings for you.
I want to know how to read the ms access form (vba form) via external application
like (notepad,notepad++).
In vb6 application can be able to read the [control name],[code] in the external application (notepad,notepad++).
but, there is no option for to do the same operation in the ms access forms.
when i open the form in the database i can ,but not in the notepad and notepad++.
It is possible or not (or) is there any other way to do this action.
You can only access the form code that is shown in the VBA editor. In VB and C# you can view the code that actually creates the control objects and initialises them (I think it is this that you are referring to). You can't see this code in Access / VBA.
If you want to edit the code in Notepad++ simply copy and paste it from the VBA code editor (which is shown when you press ALT+F11).
PS. I use a access addin called OASIS-SVN that can export all object definitions as text files, I probably does it as described here
If you want to edit VBA projects files outside from VBE, you first need to Export them (using Right-click->Export a file) and save them somewhere.
Then you'll be able to open them with notepad(++).
Don't forget to Import them back into your VBA Project after editing.
I've modified the code for UN-protecting Excel VBA Project to work with Microsoft Project from the link below.
Unprotect VBProject from VB code
But in MS Project there is always a Global.mpt(my code runs from here) and when the below line executes
projAp.VBE.CommandBars(1).FindControl(ID:=2578, recursive:=True).Execute
it always opens the VBA Project Properties of the Global.mpt file.
How do I select my Project Plan's VBA Project Properties?
Is there a Windows API function that would let me choose the second VBA Project Shown in the screen host. Launching the FindControl command after selecting the proejct should launch it corresponding VBA Project Properties(Manually tried this).
The trick is to switch over to the Project pane and "type" the first letter of the project name; I suggest you change it from the default VBAProject if possible.
SendKeys "%{F11}"
SendKeys "^r"
SendKeys "V"
DoEvents
VBE.CommandBars(1).FindControl(ID:=2578, recursive:=True).Execute
projAp.VBE.CommandBars(1).
Your code is always working with the application object, so is always looking in the Global.mpt file. try:
ActiveProject.VBProject.VBE.CommandBars(1)
It should return only items for the project.
Hi I have an Excel 2003 application which has a listview embedded in the worksheet. It no longer works on Excel 2010.
I re-registered the ocx using regsvr32 C:\Windows\System32\MSCOMCTL.OCX as per advice.
This works for listviews on forms, but not for the worksheet.
Microsoft advises that Cannot insert object can be generated if the control is form specific and an attempt is made to add to the worksheet.
Can the listview be used in Excel 2010 on a worksheet
If so how?
Otherwise a rewrite will be required.
That happened to my Excel files using ActiveX or any sort of automation. The solution was confused at the beginning but the following link will help you.
Create a batch to remove cached control type libraries (extender files *.EXD) files from Windows
Opening each of the projects (Excel with macros)
Switch the file to design mode
Open VBA Code (Alt-F11) to edit any module and press from the main menu > Debug > Compile VBAProject
Switch back to Run Mode
Save and Close File
Reopen the file & test
Form Controls stop working after December 2014 Updates
This post is about installing XLAM's without creating links. (Everyone hates links). Consider the trivial addin:
Public Function UDF_HELLO(x)
UDF_HELLO = "Hello " & x
End Function
Put this code and nothing else into a Module and save as "Hello.xlam" on the Desktop (and NOT in the default excel addins folder). Next, while HELLO.XLAM is still open, create a new XLSX workbook with the formula
=UDF_Hello("world")
in cell A1, which simply displays "Hello world" in that cell. Save the workbook and exit Excel. Now, if you reopen the workbook without the XLAM, Excel will complain about "links to other sources ...". Whether you click "Update" or "Don't Update", Excel will mangle the formula in cell A1 like this:
='C:\Documents and Settings\tpascale\Desktop\Hello.xlam'!UDF_Hello("world")
Very often this "forced-linkage" is NOT desirable. In my computing environment there is a lot of ad-hoc analysis and it makes no sense to impose an install regimen on every XLAM we throw together to solve the problem of the day. I just want to hand out XLAM files to users and let those users open them when they need them, WITHOUT having to worry about the slightest mis-step causing their formulas to get mangled.
QUESTION:
Is there a way to instruct Excel to NEVER construct external links for UDFs, and simply to use UDFs if they're loaded and return #VALUEs otherwise ?
I don't know of a way around this with .xla/.xlam add-ins.
But this issue does not occur with .xll add-ins.
These can be created in C using the Excel 2010 SDK, or in managed languages like VB.NET or C# using the free Excel-DNA library.
(Disclaimer: I'm the developer of Excel-DNA. This issue is one of the reasons I went with the .xll interface for making managed UDF add-ins.)
You can have them open the .xla file and have an Auto_Open procedure install the add-in.
http://www.vbaexpress.com/kb/getarticle.php?kb_id=693
After excel closes you can have the add-in uninstall itself.
oAddIn.Installed = False
You can give your add-in a setting for the user to not uninstall after every use by using a worksheet named something then have cell A1 equal to true or false.
I haven't tested this but hopefully it works for you.
This should work to resolve your issue though it does not instruct Excel regarding external links. I have tested it myself by creating the XLAM, saving it to my desktop, installing it in the Excel add-ins and then using it on a new workbook.
Steps:
Once you have saved the add-in, close it.
Go to Excel Options-->Add-Ins
In the Manage drop-down select Excel Add-ins and press 'Go'
In the 'Add-Ins'dialogue that appears click 'Browse' and navigate to
the add-in you just created. Select it and hit 'Ok'
If prompted to save the add-in in the add-ins folder, select 'No'.
Selecting 'Yes' may cause an error if the add-in file suffix does
not match the version of Excel being used.
Your add-in should appear in the 'Add-Ins available' scrollbox,
check its box and hit 'Ok'
Your add-in should now be active whenever you open Excel.
Test this by opening a new workbook and try using your UDF.
Best,
I usually solve this problem by:
Saving an XLA/XLAM file (outside Personal folder, of course)
Connect to it in Tools - Addins
Write pseudo macros in your current Excel file that links to those macros / functions in the XLA/XLAM file.
See the detailed instructions in my reply here.