Excel 2007 VBA FileSearch missing - excel

Someting happened with FileSearch object in Excel 2007.
In documentation it is said that FileSearch is hiden.
Does it mean that there is no way to search for files using Excel VBA anymore?

You can still search using the Dir function - lots of examples on the web if you search for 'excel 2007 vba filesearch', for example this post.

I would add a reference to the Microsoft Scripting Runtime library. That gives you access to the FileSystemObject, which lets you pretty easily test for the existence of a file and/or iterate through directories, doing your own search.

If you want to search on custom document properties, there's currently no way to do it. You have to narrow the search with Dir and open each one individually.

As Steve said you can use the FSO object to search for files using a given root path and filter expression. There is good documentation available on fitlering by extension (remember to include the extensions you want or filter by .xls) and using the objects in the FSO object model.
For an explanation (by msft) on the depreciation of FileSearch method. see - http://support.microsoft.com/kb/920229
For a basic pattern to using the FSO for searching a set of directories recursively with the FSO see -
http://support.microsoft.com/kb/185601
You can still use the
Application.GetOpenFilename
if you want to get back the path to a workbook.

Related

Integrate VBA - SAP with Outlook [duplicate]

Is there a way to view the properties on SAP GUI objects?
Like this:
But for SAP objects like the following ones:
Set SAPGuiAuto = GetObject("SAPGUI")
Set App = SAPGuiAuto.GetScriptingEngine
Set Connection = App.Children(0)
Set SAPSession = Connection.Children(0)
I ask this after reading the last part of the answer to this post: VBA general way for pulling data out of SAP
If however you want to use early binding so that your VBA editor might
show the properties and methods of the objects you are using, you need
to add a reference to sapfewse.ocx in the SAP GUI installation folder.
This is something so badly advertise by the SAP team, they should definitely do a better job there.
Basically you first of all need to add a reference to the SAP object model, the libraries that VBA will understand. Don't know how familiar are you with there references to object models. Basically, on your VBA Editor, click Tools, then References, then Browse, and find this file: "C:\Program Files\SAP\FrontEnd\SAPgui\sapfewse.ocx" (or possibly "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\sapfewse.ocx").
Now you'll be able to browse it on the Object Explorer (press F2 in the VBE), and declare the types.
You need now to familiarise yourself with the Types of this library. Some hints, they all start with Gui, like, GuiSession, GuiApplication, GuiConnection, GuiBlabla... Names are pretty explicit and intuitive.
To add on to what #Nelson_Vides has said. As he said, you will need to reference the sapfewse.ocx file, and you can view the class objects by pressing F2.
However, the IntelliSense will only be visible once you define an object from the SAP class library.
Dim userArea As GuiUserArea ' <-- For example
Now, whenever the object is used the IntelliSense will show up.
Best of luck and happy scripting!
SAP also provides documentation on their GUI objects:

VBA: Using Filesystemobject to locate workbook path

I am using the GetFolder method within FileSystemObject to locate the path of a workbook. I am then using the path to search for filenames in the same directory and extract information from files with certain names using some parameters. It works fine when working from the windows directory, however the company I work at uses Sharepoint. When accessing the Excel-workbook from Sharepoint this method no longer works. The workbook opens fine, but when I run the Macro I get an error message.
Code in question:
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(Application.Thisworkbook.Path)
Error: Unable to find path (Swedish literal error message: Det går inte att hitta filsökvägen)
Anyone with a clue as to what to do about this? I've tried some alternate ways to get the path but nothing has worked thus far.
Perhaps it would be cleaner use WinHttp object to get the SP library's contents via SharePoint REST API. It's how Microsoft wants you to approach this problem anyway. Refer to this article and SP REST API Documentation.
There is also a dirty way to this we found a few years ago. If you sync a library's contents to your File Explorer, there's a good chance FSO could work. But keep in mind that the synced library is better kept up-to-date. Also, SharePoint can handle much longer paths than FSO, so when hierarchies get deep, you'll only get the first 250-something characters.
Therefore, I'd use the API.

How to search in Enterprise Architect from an Excel worksheet?

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

generate multiple pdfs from a database

I would like to generate multiple pdfs at once. Those pdfs should pull data from a database. It can be an excel table or a relational database, doesn't matter, I can create whatever.
Using excel and javascript in adobe acrobat pro I managed to pull data into a template pdf, but for every record (row) I have in excel table I have to manually generate one pdf, then another, and so on.. and there are a lot of records, so I would like to do that automatically if possible.
Is there a way to do that? Any suggestions?
I added an image to better explain it...
Look into the Acrobat SDK, Section: "Interapplication Communication" to learn how you can control Acrobat via VB/VBA and how you can work with the JavaScript Object (JSO).
Then have a look into the "Acrobat JavaScript Scripting reference" and look at
the Doc Object with commands like .. addField and at
the Field object to set the properties of the fields.
That should do what you want, Reinhard
PS: With Open Office you can save spreadsheets as PDF and with newer version of Excel too. Wouldn't that be already enough or perhaps a mix of above and this.
Full disclosure: I founded and run Epsillion Software.
mirta, one option is Epsillion Publisher. We built it for your exact use case.
You would need to specify what your template should look like. The Epsillion team will design it for you.
You then specify what your variables are in a Word document (e.g., name, last name, date of birth). The software will process the Word and Excel files and return PDFs for you.
Templates are flexible and flow as needed.
Hope that helps. Good luck!

Programatically import Microsoft.Office.Interop.Excel namespace in VBA project

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.

Resources