HI
I am new to bo site. i have a problem. i have a report say with 50 pages. Now my problem is that i want each page of the report to be exported as different excel file. means that 50 pages = 50 excel files. ( page1 of report as excel file1, page2 of report as excel file2 and so no.)
Found the same topic again here…Again pasting the same code in this thread, it will be easier for Moderator to lock the Duplicate one and not this, we are continuing in this:
you can modify it accordingly:
Sub Refresh_for_Each_Employee()
Dim i as integer
Dim j as string
For i = 1 to 20 step 1
j = 'you must assign value of employee name here........
ActiveDocument.DocumentVariables.Item("Enter Employee Name").Value = j
ActiveDocument.refresh
ActiveDocument.ExportAsExcel "C:\foldername\EmployeeName"&j
Next i
End Sub
This topic is discussed previously, you’ll find similar routines to achieve your objective… Search in this forum using ‘report refresh’…or similar terms.
let me tell me my problem i have make a report and then export it to excel.
there are 2 ways i can make a report.
one is i just make one report with all the data say emp data with each page showing different employee detail. Now if i have 20 rec. in database then this will give me 20 pages. Now my problem is that if i save this file as excel it will come in 1 excel file. but i need each page as different excel file.
how can i make each page of report as different excel file. 20 record in database is example. i dont know how many records are there.
Second option is I promt the user to select empname. if i use this the user has to refresh the report say 20 times and save it as excel. How can i automate this process. Here also i dont know how many records are there in database.
I have gone through your post earlier, I know what you are explaining me again.!!
The code which I gave above will work for 20 employees.
If you want to run this for all the employees in your table, you can do that too. you can’t find an exact code for your requirement… you have to modify it…
Try to understand the code, use it for your purpose…to automate it.
Search for other VBA routines as well… in this forum… to get an idea… of VBA routines.
I have learned VBA through this forum, thanks to all board members for sharing their scripts, you can learn too !! But its not an overnight job!!
So search search search…try to understand OBJECT MODEL…
I have made 2 dp in the reports. 1st dp will show all the data and dp2 will
have only one column say LFC and will be used to pass the value to the prompt.
hope it is useful.
Sub ReadDataProv()
Dim DProv As DataProvider
Dim RowNum As Long
Dim lfcName As String
Dim spath As String
Set DProv = ThisDocument.DataProviders(“dp2”)
If DProv.Columns(1).Count > 0 Then 'be sure there is data
For RowNum = 1 To DProv.Columns(1).Count
lfcName = DProv.Columns(“Lfc”).Item(RowNum)
Application.Variables.Item(“Select Lfc1”).Value = lfcName
ActiveDocument.Refresh
spath = “C:” + lfcName + CStr(Year(Date)) + “.xls”
ActiveDocument.SaveAs spath
Next RowNum
End If
End Sub
thanks Bo-cheif for all the help.
this was one part of my problem. now i have to protect first 2 columns of each excel file through macro only.
I have started working on it. once i do it i will share the code. any help is most welcome.
If you really want to do the export the you can use this code to filter your data on each value in turn which avoids pratting about with unnecessary DPs
Sub DataExportByCountry()
'Dim myvar As DocumentVariable
'Dim myvar2 As DocumentVariable
'Dim reps As busobj.Reports
'Dim thereport As busobj.Report
Dim str As String
Dim OutNum As Integer
Dim strCountryList As String
Set reps = ActiveDocument.Reports
Set thereport = busobj.ActiveReport
For I = 1 To ActiveDocument.DocumentVariables.Count
Set myvar = ActiveDocument.DocumentVariables.Item(I)
If myvar.Name = "Country Iso3 C" Then
myvalues = myvar.Values(boUniqueValues)
For Each myval In myvalues
For X = 1 To ActiveDocument.DocumentVariables.Count
Set myvar2 = ActiveDocument.DocumentVariables.Item(X)
If myvar2.Name = "Billed Year/Month(Sales CM)" Then
myvalues2 = myvar2.Values(boUniqueValues)
For Each myval2 In myvalues2
'Check if a folder for this Global Name - Trim already exists
If Dir(SavePath & Trim(myval), vbDirectory) = "" Then
'if it doesn't then we create one
MkDir (SavePath & "\" & Trim(myval))
End If
'Check if a subfolder for this report type exists
If Dir(SavePath & "\" & Trim(myval) & "\" & ActiveDocument.Title, vbDirectory) = "" Then
'if it doesn't then we create one
MkDir (SavePath & "\" & Trim(myval) & "\" & ActiveDocument.Title)
End If
'Check if a subfolder for this reporting month
If Dir(SavePath & "\" & Trim(myval) & "\" & ActiveDocument.Title & "\" & myval2, vbDirectory) = "" Then
'if it doesn't then we create one
MkDir (SavePath & "\" & Trim(myval) & "\" & ActiveDocument.Title & "\" & myval2)
End If
'Check if a subfolder for this reporting output (excel or PDF)
If Dir(SavePath & "\" & Trim(myval) & "\" & ActiveDocument.Title & "\" & myval2 & "\" & "Excel", vbDirectory) = "" Then
'if it doesn't then we create one
MkDir (SavePath & "\" & Trim(myval) & "\" & ActiveDocument.Title & "\" & myval2 & "\" & "Excel")
End If
'Check if a subfolder for this reporting output (excel or PDF)
If Dir(SavePath & "\" & Trim(myval) & "\" & ActiveDocument.Title & "\" & myval2 & "\" & "PDF", vbDirectory) = "" Then
'if it doesn't then we create one
MkDir (SavePath & "\" & Trim(myval) & "\" & ActiveDocument.Title & "\" & myval2 & "\" & "PDF")
End If
'start a loop to cycle through all report tabs
For z = 1 To reps.Count
Set thereport = reps.Item(CInt(z))
str = "=<Country Iso3 C> = """ & myval & """"
thereport.AddComplexFilter "Country Iso3 C", str
thereport.ForceCompute
thereport.ExportAsText SavePath & Trim(myval) & "\" & ActiveDocument.Title & "\" & myval2 & "\" & "Excel" & "\" & thereport.Name & ".xls"
Set thereport = Nothing
Next
ActiveDocument.ExportAsPDF SavePath & Trim(myval) & "\" & ActiveDocument.Title & "\" & myval2 & "\" & "PDF" & "\" & ActiveDocument.Author
OutNum = FreeFile
Open strCountryList For Append As OutNum
Print #OutNum, myval; Chr(9); Date; Time
Close #OutNum
Next
End If
Next
Next
End If
Next
End Sub
Just drop out any sections you don’t need. It really is very simple code.
Using the code BO users have provided in this post, I have created BO report in DesktopIntelligence. I am using BOXir2. When I run the macro on the Deski, my report works perfectly fine, and I have individual excel file for each sections. It works fine.
The problem is after I export it to the CMS. I have to schedule this report to run everyday and save these excel files on a Unix server. When I schedule the report, it gives me this error:
A variable prevented the data provider Main Report from being refreshed. (DMA0008)
Even when I select the destination has default enterprise, it gives me this error. In the VBA code, I had the excel reports saved in a directory called ‘Events’ under C: drive. Since there is no C: drive in unix server, I thought it was giving me error because of that.
So I changed the path in the VBA code to point it to a directory on the unix server. I still get the same error.
I have enable and configured the destination as ‘Unmanaged Disk’ from the server properties also, and when I select the destination as ‘unmanaged disk’, I get the same error.
What am I doing wrong here? Any idea? I can post my code here if needed.