I have recently installed visio 2010. it has VBA 7.0.
I am trying to write a code to open a file dialog, choose an excel file and open it.
I used this code
Set fd = Application.FileDialog(msoFileDialogFilePicker)
but i get the following error:
Run-time error '438':
Object doesn't support this property or method
i already have the Microsoft Office 14. Object Library as reference.
Do you have an idea? what i should do?
If you use this code in Visio
Set fd = Application.FileDialog(msoFileDialogFilePicker)
the word Application refers to Visio and as you can see in Object Browser, Visio.Application class has no such method as FileDialog. Access and Excel applications have it, but not Visio.
In order to use it in Visio you need to add reference to either Microsoft Excel Object Library or Microsoft Access Object Library. Then you need to use the code below to create an instance of FileDialog (select a proper version depending on what reference did you add to your project - Excel or Access)
'If you have reference to Microsoft Excel Object Library
Set fd = Excel.Application.FileDialog(msoFileDialogFilePicker)
or
'If you have reference to Microsoft Access Object Library
Set fd = Access.Application.FileDialog(msoFileDialogFilePicker)
Like explained by #mielk, Visio does not have the Application.FileDialog. You could use the method of Excel (in this case you'll have to have Excel installed, and started to invoke its methods) or use pure WinAPI from VBA (i.e. GetOpenFileName function). This option is explained here for example:
http://visguy.com/vgforum/index.php?topic=738.0
Related
It is possible to manually save an Excel spreadsheet as a "Strict Open XML" file type in Excel when using "Save as" instead of saving it as the default workbook OOXML file, which is a "Transitional" variant of the OOXML standard. The extension is .xlsx for both Strict and Transitional file format variants of the OOXML standard.
How can I do the same thing programmatically through automated workflows in e.g. C#? The purpose is to bulk convert Transitional Excel files to Strict Excel files.
I have found these code snippets part of the Office XML SDK:
https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.conformanceclass?view=openxml-2.8.1
https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.workbook.conformance?view=openxml-2.8.1#documentformat-openxml-spreadsheet-workbook-conformance
Can I use them or other ways of doing bulk conversion from Transitional to Strict?
UPDATE: I am in dialogue with the developers of Open XML SDK in this issue.
The only way possible, that I have found after extensive research is to use Excel.Interop and have your Excel installation handle the conversion in the background. It is not a pretty solution, because it is Excel dependent, but it is a programmatic approach.
You can find the Excel.Interop package here: https://www.nuget.org/packages/Microsoft.Office.Interop.Excel
I had an issue, where the package would not find my Excel installation, so I had to make a new reference to the Excel Interop DLL on your computer.
Add reference > Browse > C:\Windows\assembly\GAC\Microsoft.Office.Interop.Excel and pick the DLL from the folder in here. I also added the DLL from the subfolder in this path C:\Windows\assembly\GAC_MSIL\office
Conversion code
using Excel = Microsoft.Office.Interop.Excel;
void Convert_Transitional_to_Strict(string input_filepath, string output_filepath)
{
Excel.Application app = new Excel.Application(); // Create Excel instance
app.DisplayAlerts = false; // Don't display any Excel prompts
Excel.Workbook excelWorkbook = app.Workbooks.Open(input_filepath); // Create workbook instance and open Excel Workbook for conversion
excelWorkbook.SaveAs(output_filepath, 61); // Save file as .xlsx Strict
excelWorkbook.Close(); // Close the Workbook
app.Quit(); // Quit Excel Application
}
PS. If anyone finds a programmatic approach using Open XML SDK or another C# framework, do still post your answer.
I built a excel macro using the "Microsoft Outlook 15.0 Object Library" reference, but when I send the file to other people they get this error: "Can’t find project or library".
This file will be used by a lot of people, so I have to add it from VBA Code.
I'm using this code that runs when you open the excel file, which is returning the following error: "Error in loading DLL"
Private Sub Workbook_Open()
Application.VBE.ActiveVBProject.References.AddFromFile "C:\Program Files (x86)\Microsoft Office\Office15\MSOUTL.OLB\"
End Sub
Do you have any idea why this is happening?
Thanks
If you still want to keep the early binding you could use the GUID in order to add the libray, i.e.
Sub AddOL_Ref()
Application.VBE.ActiveVBProject.REFERENCES. _
AddFromGuid "{00062FFF-0000-0000-C000-000000000046}", 1, 0
End Sub
Advantage of using the GUID is that it is constant and does not change with the version of the program.
Here one finds an extened discussion on dis/advantages of early resp. late binding.
You will have to remove the references & use late binding
or you can also try this. Send your code to one of the user having 2010MS.
Goto VBA > Tools > References
Check for any missing references. You may have Microsoft Outlook 15.0 Object Library showing as missing. Un-check this, browse down and select Microsoft Outlook 14.0 Object Library.
Ultimately I want to build a MS Project file using early binding from VBA behind XLS or MPP.
In order to do that, it is my understanding that you should go to Tools--> References and select the Microsoft Project XX.X Object Library.
Unfortunately, it wasn't in the list.
The References pop-up allows you to browse, and select the reference library manually. Great! But, where do I look, and what file do I select to import this reference?
Assuming you are looking in Excel VBA References's list, it should just show up. Here's mine:
Note that I see it as Microsoft Office Project XX.X Object Library, you asked about Microsoft Project XX.X Object Library (lacking Office).
My environment is Win10; both Excel 2016 32-bit and Project 2016 32-bit are installed.
Perhaps try re-installing your Office components? Perhaps try making sure you have both the same bit architecture (32 or 64).
I'm a trainee and my boss asked me to make a script that searches for packages in Enterprise Architect from a name. The base is in Excel and count all the use-cases, the count I already did, but the search I could not get yet.
*edit: the count im already made, but i need a search metod, get all names from a excel file and searchs this names on Ea
You can do this with the ActiveX Object functionality with Jscript in EA, basicaly you can open the excel sheet directly from your script and read the data
ActiveX Object Jscript Reference
ActiveXObject in Sparx EA
VBScript, JScript and Javascript can each create and work with ActiveX
/ COM objects. This can help you to work with external libraries, or
to interact with other applications external to Enterprise Architect.
For example, the Scripting.FileSystemObject Class can be used to read
and write files on the local machine. The syntax for creating a new
object varies slightly for each language, as illustrated by these
examples:
VBScript:
set fsObject = CreateObject("Scripting.FileSystemObject")
JScript:
fsObject = new ActiveXObject("Scripting.FileSystemObject");
Javascript:
fsObject = new COMObject("Scripting.FileSystemObject");
Note: from my personal experience, this doesn't work with a JavaScript script, use Jscript or VBscript
I'm trying to programatically import Microsoft.Office.Interop.Excel namespace into my vba project. I found this site
that displays how to import it manually, but I'm giving this project that I've been working on to people that won't know how to import it. Can anybody please help?
I assume from your question that your VBA code uses a reference to the Microsoft Excel 12.0 (or other version) library - and that your user gets an error as the reference cannot be found. In this case, you have two options:
Instead of referring to the v12 library, refer to an older library, e.g. from Excel 2003. To do so, search the net for this library and install it - or simply "relink" your file in an Office 2003 installation before shipping
Use late binding instead of early binding. In this case, you do not add a reference to the Excel library at all. Instead, you declare your objects as type Object(instead of Excel.Workbook, Excel.Application, etc.). To create a new object, instead of using Set objExcelApp = New Excel.Application, you must now use CreateObject (for new objects) or GetObject (for existing objects, e.g. an existing, running application): Set objExcelApp = CreateObject("Excel.Application"). Any later code will continue to work as usual (though it might be a tiny bit slower due to the late binding).
For further reading, check this answer.