Question

How can I create a SSIS package that reffreshes Excel document connected to SQL data. I need to then save the file to 2 locations using YYYYMM ending?

Asked by: zaronline

Hi,

I run monthly reporting. SPs generate the reports into tables in SQL 2000 server.
I have a linked workbook that contains links to the report table in SQL.

Everymonth a SSIS package runs the SPs to generate the reports in SQL server.

I then manually go to each report and refresh all sheets in the workbook.
Then I save the template and then save the file into 2 locations.
Is it possible to do this task using SSIS to avoid the need to manually do this.

the report structures are:

TEMPLATE: REPORT YYYYMM.Xls

Final report: G:\...\Report 200903.xls
                     F:\...\Report 200903.xls

PDF FILE SAVED AS: (Using Excel 2007's SAVE AS PDF option)
                      F:\...\Report 200903.pdf
I also save some of the reports as PDF sheets.
Can this also be done using SSIS ?

Thanks,

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-04-26 at 20:14:50ID24357093
Tags

SSIS Excel macro

Topics

SSIS

,

Automation

,

Microsoft Excel Spreadsheet Software

,

.NET

,

Microsoft Visual Basic.Net

Participating Experts
2
Points
250
Comments
38

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. SSIS
    validation of date field in SSIS tool
  2. Refreshing a sheet in a workbook with SSIS
    Hi Experts, I have a workbook(MyWorkbook) with a sheet(Products) the Products sheet is hidden and becomes unhidden as soon as you enable your macros. The Products sheet contains a range of data that I get from a view in SQL. I would like to automate the refreshing of data in...
  3. SSIS
    I had Date format yymmdd. I want to convert to yy/mm/dd. If i try to do by formatting cells in Excel Sheet, it is giving some other date. How can i do it..........Please help me out........
  4. How to import multiple excel sheets into sql using ssis
    I have an Excel workbook with over 9 million records.. Multiple sheets.. I'm new to SSIS and I'm wondering if someone would tell me step by step how to create a package that would import my data from the multiple sheets into one table in SQL Server 2008
  5. SSIS Date
    I am creating a SSIS package to extract data from a flat file. In the flat file there is a date column in the 'YYYYMM' format. I need to convert it into a datetime, using 01 as the DD part. For exampe if the input value is '201001' in YYYYMM format. The converted value sho...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: nmcdermaidPosted on 2009-04-27 at 21:22:05ID: 24247574

Yep. You do the following:

1. Install Excel on the server that SSIS is running on (can sometimes be an issue)
2. Record an Excel macro which does what you need it to do (refresh data, Save As etc.)
3. Convert that macro from VBA to .Net code
4. Paste the code into a script task in SSIS

There are some other minor complications but thats the gist of it. I can give you more info if need be.

 

by: zaronlinePosted on 2009-04-28 at 16:50:50ID: 24256289

Hi,

1. SSIS package runs on desktop with Excel installed on it.

2. I have the Excel macro that refreshes all:


Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.Office.Interop.Excel

Public Class ScriptMain

   Public Sub Main()
       Dim excel As New Microsoft.Office.Interop.Excel.Application
       Dim wb As Microsoft.Office.Interop.Excel.Workbook
       wb = excel.Workbooks.Open("C:\Data\Test.xls")
       wb.RefreshAll()
       wb.Save()
       wb.Close()
       Dts.TaskResult = Dts.Results.Success
   End Sub

End Class

2A. I also need a way to save  the file into 2 locations as below (with current YYYYMM in filename) :

TEMPLATE: REPORT YYYYMM.Xls

Final report: G:\...\Report 200903.xls
                    F:\...\Report 200903.xls

2B. I then also need to save the files as PDF

PDF FILE SAVED AS: (Using Excel 2007's SAVE AS PDF option)
                     F:\...\Report 200903.pdf

3. I do not know how to  Convert that macro from VBA to .Net code. IS THERE A PROGRAM I can use to do this?

4. I tried to copy the macro directly to SSIS Script task and it did not work too well.

I did find a piece of code that was ment to run macros from SSIS:


'===================
strExcelFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "test.xls"
strMacroName = "run_macro"
Set objExcel = CreateObject("Excel.Application")
Set objWB = objExcel.Workbooks.Open(strExcelFile)
objExcel.Visible = True
objWB.Application.Run strMacroName
objWB.Close False
objExcel.Quit
'===================

But I am unsure how I set this up in a SSIS package.

It would be greate if I could get a sample SSIS package that does these tasks.

 

 

by: nmcdermaidPosted on 2009-05-02 at 00:34:09ID: 24285213

So when you pasted that code in, what error did you get? It looks like it should have worked to me. Once you get it working we just add additional lines to do the extra saving etc.

 

by: zaronlinePosted on 2009-05-03 at 16:29:13ID: 24291670

Hi Expert,

I am not sure how to setup the SSIS package script task paramaters to execute the Run macro in excel script.

Is there any settings I need to change ? Do I use the ActiveX Script or Script task to perform this task?

What is the VBA macro script I can use to save the files to different locations?

Thanks for you help.

If I send a copy of the SSIS package I have made so far could you correct the bugs in it for me?

 

by: zaronlinePosted on 2009-05-03 at 17:15:29ID: 24291826

Hi Expert,

I have attached the error I get when I try to use the SCRIPT Task in SSIS. and the SSIS package that I made to run an excel "save as" task.

I am not able to run the script below due to this error.

'===================
strExcelFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "test.xls"
strMacroName = "run_macro"
Set objExcel = CreateObject("Excel.Application")
Set objWB = objExcel.Workbooks.Open(strExcelFile)
objExcel.Visible = True
objWB.Application.Run strMacroName
objWB.Close False
objExcel.Quit
'===================  

Any help would be appreciated.

 

by: nmcdermaidPosted on 2009-05-03 at 21:09:43ID: 24292454

The script that you posted above will only run in an ActiveX script task (not a Script Task). As ActiveX script tasks are only there for backwards compatability, I don't suggest you use it.

What happens when you run the other script (reproduced below) in a Script Task?

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.Office.Interop.Excel

Public Class ScriptMain

  Public Sub Main()
      Dim excel As New Microsoft.Office.Interop.Excel.Application
      Dim wb As Microsoft.Office.Interop.Excel.Workbook
      wb = excel.Workbooks.Open("C:\Data\Test.xls")
      wb.RefreshAll()
      wb.Save()
      wb.Close()
      Dts.TaskResult = Dts.Results.Success
  End Sub

End Class

 

by: nmcdermaidPosted on 2009-05-04 at 15:49:18ID: 24300087

I tried the above code myself but my install can't access the interop assemblies (the Imports Microsoft.Office.Interop.Excel part).

I am going to put in an admin comment to add this to the .Net zone as this is getting out of my area of expertise and I may not have to time to help properly with htis.

Suffice to say, if you just want to get this working, you can paste this bit of code into an ActiveX script task and it will work. Its not really recommended though as eventualy this task will be removed from SSIS.

'===================
strExcelFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "test.xls"
strMacroName = "run_macro"
Set objExcel = CreateObject("Excel.Application")
Set objWB = objExcel.Workbooks.Open(strExcelFile)
objExcel.Visible = True
objWB.Application.Run strMacroName
objWB.Close False
objExcel.Quit
'===================  

 

by: zaronlinePosted on 2009-05-04 at 21:21:40ID: 24301535

Hi Expert,

I am having no luck running the ActiveX script in SSIS. ive attached the error I recieve. Could I get a sample working version of this.

I have used the following SCRIPT TO RUN:


'===================
strExcelFile = "RCTI YYYYMM.xls"
strMacroName = "mymacro"
Set objExcel = CreateObject("Excel.Application")
Set objWB = objExcel.Workbooks.Open(strExcelFile)
objExcel.Visible = True
objWB.Application.Run strMacroName
objWB.Close False
objExcel.Quit
'===================  

 

by: nmcdermaidPosted on 2009-05-06 at 19:40:20ID: 24321782

Well, if we pursue the .Net solution just a little further (I am reluctant to support ActiveX in SSIS)

If you drop a Script Task on your page and go into the editor (Design Script)

Now go to Project/Add Reference

Do you see

Microsoft.Office.Interop.Excel

in the list anywhere?

Did you try my suggestion at comment ID 24292454?

 

by: zaronlinePosted on 2009-05-10 at 21:42:30ID: 24351517

Hi Expert,

I an not able to find the Interop in the Add reference panel.

I have tried your suggestion in  comment ID 24292454 however I get the Red X symbol with an error.

Any other way or is there a way to gain this reference added?

Thanks

 

by: nmcdermaidPosted on 2009-05-11 at 05:12:25ID: 24353621

I have created this question:

http://www.experts-exchange.com/Programming/Languages/.NET/Q_24387555.html

To try and work it out the Interop assembly thing but no one has been able to help so far.

How about my suggestion at id 24300087, did you try that? (in an ActiveX script task)

I think we can use the CreateObject function in .Net to get around that missing assembly. We'll basically need to convert your code and macro to .Net

 

by: zaronlinePosted on 2009-05-11 at 16:27:58ID: 24359982

Hi Expert,

I have already tried that in Active X. Please refer to my comment on 24301535. I have attached the DTS package I created and error images.

Could you please have a look at the package and let me know if I am doing anyting incorrect?

Thanks,

 

by: nmcdermaidPosted on 2009-05-12 at 03:52:51ID: 24363094

The attached code appears to work intermittently - paste it into a script task. (not ActiveX)

Because we are using late binding (CreateObject, in turn because we can't get the Interop to work), we need to set a tick box:

Inside the actual editor, Press Project / Properties. Under build, untick 'Option Strict On by default'

You'll need to edit the code to

1. Use the paths you want.
2. Add another SaveAs line to save another copy of the workbook
3. If an error occurs, it will show it in a messagebox. You may not want this when its finally working

I ran this a few times but it did not seem to let go of the Excel object.

So basically it is partially working, until I can get time to take a closer look.

Have a look and get back to me.

' Microsoft SQL Server Integration Services Script Task
' Write scripts using Microsoft Visual Basic
' The ScriptMain class is the entry point of the Script Task.
 
Imports System
 
Public Class ScriptMain
 
    Public Sub Main()
        Dim sPeriod As String
        Dim oExcel As Object
        Dim oWB As Object
 
        Dts.TaskResult = Dts.Results.Success
 
        Try
            oExcel = CreateObject("Excel.Application")
            oWB = oExcel.Workbooks.Open("D:\KB\ExpertsExchange\Q_24357093\REPORT YYYYMM.xls")
            sPeriod = (Format(DateTime.Today, "yyyyMM"))
            Call oExcel.ActiveWorkbook.RefreshAll()
            Call oExcel.ActiveWorkbook.SaveAs("D:\KB\ExpertsExchange\Q_24357093\REPORT " & sPeriod & ".xls")
        Catch ex As Exception
            MsgBox(ex.Message)
            Dts.TaskResult = Dts.Results.Failure
        End Try
 
        Call oWB.Close(False)
        oExcel.Quit()
        oExcel = Nothing
 
    End Sub
 
End Class

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:

Select allOpen in new window

 

by: zaronlinePosted on 2009-05-12 at 17:03:44ID: 24370579

Hi Expert,

Thank you for this. I have actually compiled an Excel macro that loops through the entire folder and refreshes and saves the data as required. I have over 50 reports, so that was the quickest solution.

I need SSIS to initiate the running of that macro. How can I modify your code to make it execute a macro called "RUN_ALL_MACRO"

 

by: nmcdermaidPosted on 2009-05-13 at 02:34:47ID: 24372763

Thats what  I tried doing first but there were so many Excel security issues around macros, I figured this was the simplest way.

You can try the code below (untested). You should make sure that you untick 'Option Strict On by default' as described above.

Try it and see.

Imports System
 
Public Class ScriptMain
 
    Public Sub Main()
        Dim oExcel As Object
        Dim oWB As Object
 
        Dts.TaskResult = Dts.Results.Success
 
        Try
            oExcel = CreateObject("Excel.Application")
            oWB = oExcel.Workbooks.Open("D:\KB\ExpertsExchange\Q_24357093\REPORT YYYYMM.xls")
            oWB.Application.Run "mymacro"
        Catch ex As Exception
            MsgBox(ex.Message)
            Dts.TaskResult = Dts.Results.Failure
        End Try
 
        Call oWB.Close(False)
        oExcel.Quit()
        oExcel = Nothing
 
    End Sub
 
End Class
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:

Select allOpen in new window

 

by: zaronlinePosted on 2009-05-25 at 17:31:06ID: 24469462

Thank you for the update. I have been ill last few days. I will try the solution this week and leave feedback.

 

by: zaronlinePosted on 2009-06-01 at 20:49:28ID: 24523768

Hi Expert,

I just tested this package. Still getting the same error message as in post 24291826.

Could some one provide me with a sample working SSIS package. I could check if there is anything I am doing wrong on my one.

Thanks

 

by: nmcdermaidPosted on 2009-06-03 at 16:53:09ID: 24542527

Did you untick 'Option Strict On By Default'?. This will allow late binding, which in turn will allow your script to compile (assuming there are no other problems), which in turn will remove the error in comment 24291826.

I have attached a package where this option is unticked and the code compiles OK.

Once you have got around the compilation error, I still can't guarantee that it will work as there are a lot of annoying security lockdowns that stop macros running.

  • Package.txt
    • 137 KB

    Note: Option Strict On By Default is unticked

 

by: zaronlinePosted on 2009-06-04 at 15:48:59ID: 24552104

Hi Expert,

I was finally able to run the package. But again the process errored out.

I have attached the error message.

Something to do with Excel macros being disabled.

Any way to get around this issue?

 

by: zaronlinePosted on 2009-06-04 at 15:51:14ID: 24552120

Sorry attached the wrong error immage. Please find the error message for post 24552104.

 

by: nmcdermaidPosted on 2009-06-04 at 17:44:51ID: 24552702

Thats what I meant earlier on about all the macro security making things really difficult. Macros are heavily locked down and it could take you some time to work out how to unlock it.

It should be as easy as setting an 'enable' flag somewhere. Go into your Excel sheet and see if it warns you about macros being locked. If so, unlock them and save the sheet. You may need to do some kind of Excel wid or machine wide macro unlock thing, which of course makes your machine susceptible to macro attacks (which really are a thing of the past if you ask me)

What version of Excel do you have? If its 2007, do you want to post your Excel sheet to me and I can take a look.

If we can't unlock the macro's in the sheet then we need to convert the macro to VBScript (not too hard) and paste the macro into the script task.

It is not an ideal solution - you really are better off with the macro code in Excel - but it is an option.

 

by: nmcdermaidPosted on 2009-06-04 at 17:52:07ID: 24552746

This site

http://office.microsoft.com/en-us/ork2003/HA011403071033.aspx

indicates that for 2003, you can either set the Excel macro security to low, or digitally sign the macro. Why don't you set security to low and try your code again.

It is remotely possible that the macro doesn't exist (as per the message) but I assume you've already checked that, and I'm certain it is security related.

 

by: jbentleypPosted on 2009-06-08 at 10:39:55ID: 24574423

Use SSIS w/o Excel macros...

 

by: zaronlinePosted on 2009-06-11 at 19:06:26ID: 24608611

Hi Expert,

Good news on one of these samples!!

I have tried ID: 24363094 and this seems to work ok for a simgle file. But there is an issue that the data is not yet refreshed and the file is attemption to save.

How can I make the query wait for the data to refresh before I save the file?

 

 

by: zaronlinePosted on 2009-06-11 at 19:14:19ID: 24608643

I am getting the following error when I try to correct this issue by switching the display alerts off.

How can I set the displayAlerts property off when running this Script task?

 

by: nmcdermaidPosted on 2009-06-11 at 20:26:43ID: 24608914

Glad you made some progress.

Take the CALL out from the front of it.

Call is used when calling a method

Call is not used when setting a property (which is what you're doing)

 

by: zaronlinePosted on 2009-06-13 at 05:07:51ID: 24618820

Thank you for the tip. Is this  .NET script that I am using in this code?

 

by: nmcdermaidPosted on 2009-06-13 at 18:22:27ID: 24621488

If its inside a script task then yes its .Net script.

The ActiveX script task is for backwards compatability. It is VBScript code (comparable to VB 6)

You are using .Net script to call a COM object by late binding, which is a bit of a mish mash. COM is more used back in VB6 days. thats why we had to mess about to get it to work.

Hope that makes sense.

 

by: zaronlinePosted on 2009-06-15 at 17:27:56ID: 24634140

Thanks for that tip that worked fine for the ODBC Connected datasets.

It does not however update pivot tables in the dataset. Is there another .NET comand that can update the pivot tables?

 

by: nmcdermaidPosted on 2009-06-15 at 21:15:29ID: 24634825

Apparently the RefreshAll method is meant to refresh them. But if it isn't, you can try using the code on this page:

http://stackoverflow.com/questions/70947/how-can-i-refresh-all-the-pivot-tables-in-my-excel-workbook-with-a-macro

Which shows how to cycle through all pivot tables and refresh them.

I have converted it for you and attached below. Just plug it in before the SaveAs line.

dim w, p
for each w in oExcel.ActiveWorkbook.Worksheets
 
  for each p in w.pivottables
    p.refreshtable
    p.update
  next
next

                                              
1:
2:
3:
4:
5:
6:
7:
8:

Select allOpen in new window

 

by: zaronlinePosted on 2009-06-16 at 16:06:38ID: 24643429

Excelent result Expert. This worked like a charm.

I guess there is more than 1 way to skin a cat.

What the MACRO did was loop through a folder and find all the EXCEL files in that folder and refresh each file then saving it to 2 locations.

It seems we have built every thing except the first part: Loop through the folder collect all the Excel sheet names and execute the code for all the Excel files one by one!!.

If this is possible in .NET then I don't need to use the macro in excel at all.

Is there a way to do this?

So far I have the following codes working fine for 1 file. we need to do this for all excel files in say: C:\myFolder\ExcelTemps\

' Microsoft SQL Server Integration Services Script Task
' Write scripts using Microsoft Visual Basic
' The ScriptMain class is the entry point of the Script Task.
 
Imports System
 
Public Class ScriptMain
 
    Public Sub Main()
        Dim sPeriod As String
        Dim oExcel As Object
        Dim oWB As Object
 
        Dts.TaskResult = Dts.Results.Success
 
        Try
            oExcel = CreateObject("Excel.Application")
            oWB = oExcel.Workbooks.Open("D:\KB\ExpertsExchange\Q_24357093\REPORT YYYYMM.xls")
            sPeriod = (Format(DateTime.Today, "yyyyMM"))
            Call oExcel.ActiveWorkbook.RefreshAll()
 
	dim w, p
	for each w in oExcel.ActiveWorkbook.Worksheets
 
	  for each p in w.pivottables
    	  	p.refreshtable
	  	p.update
  	    next
	next
 
 
            Call oExcel.ActiveWorkbook.SaveAs("D:\KB\ExpertsExchange\Q_24357093\REPORT " & sPeriod & ".xls")
        Catch ex As Exception
            MsgBox(ex.Message)
            Dts.TaskResult = Dts.Results.Failure
        End Try
 
        Call oWB.Close(False)
        oExcel.Quit()
        oExcel = Nothing
 
    End Sub
 
End Class
  

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:

Select allOpen in new window

 

by: nmcdermaidPosted on 2009-06-16 at 17:12:41ID: 24643786

Yep there are many ways to skin a cat :)

For example to loop through a file you could write some VB.Net code to do it..... or you could use the For Eacg iterator in SSIS.

It depends what you would like to learn more about - SSIS or VB.Net?

I actually suggest SSIS if you are doing a lot of data integration stuff.

 

by: zaronlinePosted on 2009-06-16 at 17:27:55ID: 24643855

Hi Expert,

I will be gready and ask to know how to do this in both SSIS and VB.NET,

As I am having a winning streak with VB.NET could you please let me know how this can be done in VB.NET first?

 

by: nmcdermaidPosted on 2009-06-16 at 18:27:39ID: 24644180

VB6 is my strong point, not VB.Net, but I will have a go.

Here's some coded here:

http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.adonet/topic50872.aspx

I'm a bit pressed for time so why don't you take a look and see if you can work out how you can fit it in. After some changes, the variable strFileName now contains your workbook name.

A very interesting thing is that they are using Microsoft.Interop, but they are not using Microsoft.Interop.Excel - maybe thats the issue we were having earlier when trying to use Interop.

 

by: zaronlinePosted on 2009-06-21 at 18:53:28ID: 24679322

Hi Expert,

I am working with this code from the website you provided. Just a quick question, is this an ACTIVEX script or script task?

Import these libraries:

Imports System.IO
Imports Microsoft.Office.Interop

Then in your method body:

       Dim objDirectory As Directory
       Dim arrFileNames As String() = objDirectory.GetFiles("X:\ExcelWorkbooks")
       Dim strFileName As String
       Dim objExcelApplication As New Excel.Application
       Dim objExcelWorkbook As Excel.Workbook
       Dim objExcelWorksheet As Excel.Worksheet

       For Each strFileName In arrFileNames
           objExcelWorkbook =
objExcelApplication.Workbooks.Open(strFileName)
           For Each objExcelWorksheet In objExcelWorkbook.Worksheets
               ' Do something with objExcelWorksheet.Name
           Next
           objExcelWorkbook.Close()
       Next

       objExcelApplication = Nothing

 

by: nmcdermaidPosted on 2009-08-22 at 15:40:09ID: 25160539

Sorry I didn't respond - that would be a script task.

Regarding comment 24351517 way up the top, I found some info on using the interop. Apparently SSIS can only see assemblies stored in limited locations. (somewhere under windows I think). It can't see them stored in other standard assmbly locations.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...