Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Script using excel to complie a New Workbook

Posted on 2008-06-24
1
Medium Priority
?
630 Views
Last Modified: 2013-11-05
I have developed a script which goes into a shared folder and opens up N workbooks and copies sheet 1 from each of N to a master workbook.  As it copies into the Master workbook it creates a sheet that has all of the worksheets data on it with an added column of Producer which is grapped from the file name.  The problem that I am having is with formatting the Master Sheet's page breaks I can add a page break where I want it however I can not remove the Automatic PageBreak that is inserted by execl.  Not the sub format master which contains the insertion of the page break.  I have tried to preformatt the worksheet with the initalizemaster sub to set pagebreaks to none.   Any help would be apperciated.  The complete script is below.

'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 2007
'
' NAME: Consolodate PipeLine XlS
'
' AUTHOR: John Finner , Gateway Bank and Trust
' DATE  : 6/16/2008
'
' COMMENT: This will consoldate Pipeline Spreadsheets into one master sheet
'
'==========================================================================
'Global Variables
'=============================================================================================
Dim objExcel,objMasterWorkbook,objMasterWorksheet,objFso,objRange
Dim strPath,strdrive,i
Dim ArrFiles
Dim IntBookMark
'=============================================================================================
'Initialize Globals
'=============================================================================================
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True 'set to true for debug
Set objMasterWorkbook = objExcel.Workbooks.Add
Set objFSO = CreateObject("Scripting.FileSystemObject")
strdrive = "b:"
strPath = "\\ec01XPAdmin01\temp"
i = 0
IntBookMark = 2
InitializeMaster()
drivemapper strdrive,strPath
GetFileNames (strdrive+"\")

'Process PipeLines
'=============================================================================================
Do While i <> UBound(ArrFiles)
ProcessUserPipeline strdrive+"\"+ArrFiles(i),ArrFiles(i)
i = i +1
IntBookMark = IntBookMark + 1
Loop
'=============================================================================================

FormatMaster ()
CleanUp()
Sub InitializeMaster()

Set objMasterWorksheet = objMasterWorkbook.Worksheets(1)
objMasterWorksheet.Cells.PageBreak = xlPageBreakNone
With objMasterWorksheet
.name = "Master List"

End With

With objMasterWorkbook
.Worksheets("sheet2").delete
.Worksheets("sheet3").delete
End With

With objExcel
.Cells(1,1).value = "Producer"
.Cells(1,2).value = "Prospect"+Chr(10)+"Name"
.Cells(1,3).value = "Lead"+Chr(10)+" Source"
.Cells(1,4).value = "Exp."+Chr(10)+" Date"
.Cells(1,5).value = "Stage"
.Cells(1,6).value = "Total"+Chr(10)+" Revenue"
.Cells(1,7).value = "%"
.Cells(1,8).value = "Expected"+Chr(10)+"Revenue"
.Cells(1,9).value = "Comments"
End With
Set objRange = objExcel.Range("A1:I1")
With objRange
.Interior.ColorIndex = 1
.Font.ColorIndex =2
.Font.Size =10
.Font.Bold = True
End With


End Sub
Sub ProcessUserPipeline (strFileName,strSheetName)
'Global Dependancies
'=============================================================================================
'objExcel,objMasterWorkBook,objMasterWorkSheet
'=============================================================================================
'Variables
'=============================================================================================
Dim objSlaveWorkSheet
Dim IntStartingPoint,IntEndingPoint,intLoopControl
'=============================================================================================
strSheetName = MakeWorkSheetName(strSheetName)
intLoopControl = 2
'WScript.Echo strSheetName 'debug
'Copy Work Sheet
'=============================================================================================
WScript.Echo "File Name "&strFileName
With objExcel
.Workbooks.Add(strFileName)
.Workbooks(IntBookMark).worksheets(1).copy(objMasterWorkbook.Worksheets(1))
End With
'=============================================================================================
'Rename Worksheet
'=============================================================================================
Set objSlaveWorkSheet = objMasterWorkbook.Worksheets(1)
objSlaveWorkSheet.name = strSheetName
'=============================================================================================
'Copy Data to Master Worksheet
'=============================================================================================
IntStartingPoint = FindEndOfSheet (objMasterWorksheet)
IntEndingPoint = FindEndOfSheet (objSlaveWorkSheet) 'this may be wrong -1
WScript.Echo IntStartingPoint
WScript.Echo "Ending Point for "&strSheetName&" "&IntEndingPoint
Do While intLoopControl <> IntEndingPoint
      objMasterWorksheet.Cells(IntStartingPoint,1).value = strSheetName
      objMasterWorksheet.Cells(IntStartingPoint,2).value = objSlaveWorkSheet.Cells(intLoopControl,1)
      objMasterWorksheet.Cells(IntStartingPoint,3).value = objSlaveWorkSheet.Cells(intLoopControl,2)
      objMasterWorksheet.Cells(IntStartingPoint,4).value = objSlaveWorkSheet.Cells(intLoopControl,3)
      objMasterWorksheet.Cells(IntStartingPoint,5).value = objSlaveWorkSheet.Cells(intLoopControl,4)
      objMasterWorksheet.Cells(IntStartingPoint,6).value = objSlaveWorkSheet.Cells(intLoopControl,5)
      objMasterWorksheet.Cells(IntStartingPoint,7).value = objSlaveWorkSheet.Cells(intLoopControl,6)
      objMasterWorksheet.Cells(IntStartingPoint,8).value = objSlaveWorkSheet.Cells(intLoopControl,7)
      objMasterWorksheet.Cells(IntStartingPoint,9).value = objSlaveWorkSheet.Cells(intLoopControl,8)
      intLoopControl = intLoopControl + 1
      IntStartingPoint = IntStartingPoint + 1
Loop
'=============================================================================================
End Sub
Function MakeWorkSheetName (strtmp)
strtmp = replace(strtmp,".xls","")
MakeWorkSheetName= strtmp
End Function
Function FindEndOfSheet (objTempSheet)
Dim strEOS
strEOS = 1
Do Until Len(objTempSheet.cells(strEOS,1).value) = 0
      strEOS = strEOS + 1
Loop
FindEndOfSheet = strEOS
End Function
Sub GetFileNames(strFolderToGet)
'Dependancies
'=============================================================================================
'ObjFso as File system Object
'ArrFiles
'=============================================================================================
'Variables
'=============================================================================================
Dim objFolder,objFiles
Dim strFileList
'=============================================================================================
'Build File List into a String
'=============================================================================================
Set objFolder = objFSO.GetFolder (strFolderToGet)
Set objFiles = objFolder.files
For Each file In objFiles
      strFileList = file.name+";"+strFileList
Next
'=============================================================================================
ArrFiles = Split(strFileList,";")
End Sub
Sub drivemapper (drive,share)
'Map Network drive
Dim network,drives,i
Set network = WScript.CreateObject("WScript.Network")
Set drives = network.EnumNetworkDrives
For i=0 to drives.count -1 Step 2
If LCase(drive)= LCase(drives.item(i)) Then
network.RemoveNetworkDrive drive, True,True
End If
Next
network.MapNetworkDrive drive, share
End Sub
Sub CleanUp ()
Dim objNetwork
Set objNetwork = WScript.CreateObject("WScript.Network")

objNetwork.RemoveNetworkDrive strDrive
End Sub
Sub ScreenPrintArray (arrTemp)
'This Prints out any arr elements
'Variables
'=============================================================================================
Dim intArraySize,i
'=============================================================================================
'Initialize Variables
'=============================================================================================
i=0
intArraySize = UBound (arrTemp)
'=============================================================================================
WScript.Echo "There are "&intArraySize&" elements in the array"
Do While i <> intArraySize
      WScript.Echo "Element "&i &"is : "&arrTemp(i)
      i = i+1
Loop
End Sub
Sub FormatMaster
Const xlToRight = -4161
Const xlLandscape = 2
Const xlPageBreakNone = -4142
Const xlPageBreakManual  = -4135
Dim objActiveCell

Set objRange = objMasterWorksheet.UsedRange
objRange.EntireRow.Autofit()
objRange.EntireColumn.Autofit()

objMasterWorksheet.Cells.PageBreak = xlPageBreakNone

Set objRange = objMasterWorksheet.range("j1")
objRange.pageBreak = xlPageBreakManual
'Set objRange = objMasterWorksheet.range("F1")
'objRange.pageBreak = xlPageBreakManual
'Set objRange = objMasterWorksheet.range("F1")
'objRange.pageBreak = xlPageBreakNone

Set objRange = objMasterWorksheet.Range("D:D")
objRange.NumberFormat = "M/D/YYYY"
Set objRange = objMasterWorksheet.Range("F:F")
objRange.NumberFormat = "$#,##0.00"
objRange.pageBreak = xlPageBreakManual



With objMasterWorksheet
.pagesetup.CenterHeader = "&""Arial,Bold""&14Gateway Insurance Services, Inc." & Chr(10) & "Sales Pipeline Report"
.pagesetup.Orientation = xlLandscape
End With



End Sub
0
Comment
Question by:Mark Pavlak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 24

Accepted Solution

by:
purplepomegranite earned 1500 total points
ID: 21861355
This question has already been asked and answered.  Depending upon your set-up, you may not be able to remove the automatic pagebreaks, but pretty much all the available options are detailed in this question: http://www.experts-exchange.com/Q_22056182.html
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question