We are exporting our data from the report to excel via vba, then sending that excel file off to Outlook, which in turn, sends it off to our vendors.
How do I (after creating the excel file via vba) auto fit or auto size or whatever excel calls it to make every column the width of the contents so that the receiver of this information doesn’t need to expand the cells to see it?
You’ll need to add the Excel object library to the references in your macro (Select Tools + References and check the Excel option). From that point you can actually start Excel in the background and drive it from BusinessObjects. Tell it to open the file, apply the logic that Jenn gave you earlier, save and close the file.
It’s not difficult, but you do have to have Excel installed and available. If this macro is to be run on a server, that may be a bit of an issue. Some folks don’t like to have apps running on their servers.
To run applications on a server, for things like opening and reformatting a spreadsheet, or sending email from Outlook, do you need to have a user permanently logged into the server? Or does it depend on what you’re trying to do?
We have both. We have an NT admin account setup that is always running the pc. It has excel on the server because we had to send out Excel spreadsheets via email, which means it has Outlook installed too. I have the dll’s registered already for both outlook and Excel. I just have never written the statements for Excel to open the file, autofit and re-save. Wondered what the syntax.
Our box doesn’t get used much and that is all that is on the box for our use. It is dedicated and no other use has been designated on the box.
Ok, so I finally got around to working with this, and my main problem is still not working with the suggestions below to incorporate the :
Cells.Select
Selection.Columns.Autofit
It is almost like it doesn’t recognize the range of columns or rows. This code, once I email it or put the excel file on my hard drive, makes this xls file unusable. I implemented it using most of the code that was from the code samples. I believe I understand the code pretty well that was written for downloading BO reports to Excel spreadsheets.
So don’t you have to put something in here to specify what range of columns or cells?
I have found the code from the code samples that deletes the worksheets 1, 2, 3 from Excel when converting the BO reports to Excel using VBA, but I see it is commented out. I get it to work, if I answer the EXCEL dialog box that pops up (because I allow interaction) saying “Am I sure I want to delete the sheet requested?” when running my vba script.
How do I answer that box with BCA, without interaction from the user. Essentially, how do I set the dialog box answer to Yes or OK, so that it deletes sheet 1,2,3 before I save the workbook in VBA, using code instead of interaction from someone?
Application.Interactive = False only works for BO functions, not Excel dialog boxes.
You can use the following to select all of the “used” cells on a page (if you don’t want to just use Cells.Select. It’s useful for counting the number of rows used, etc. Also note… if you are still having issues, make sure that the Worksheet you want to select is activated first (as in the following example):
I will give this a try. When you turn the Alerts off, does it answer it as the default? If it doesn’t present the question to begin with, then does it just do the action requested?