Advertisement

03.24.2007 at 10:44AM PDT, ID: 22470263
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

VB Script to create and format Excel file
Tags: excel, file, script, format, vb
I have created a DTS Package in SQL the runs a query and creates an Excel file with that data.  I would like to be able to create the file with some basic formatting (column widths, row height, font & font  size by row or column.  The DTS package creates a VB Transformation script that I will attach below.  Does anyone if it is possible and if so, how I can add sript to this that will include the type of formatting mentioned above?  FYI...I know very little about programming and Visual Basic.  I just started to teach myself some basics but I'm about as gren as it gets.  Thanks in advance for any help you can provide!  Brett

Here is the script:

'**********************************************************************
'  Visual Basic Transformation Script
'  Copy each source column to the
'  destination column
'************************************************************************

Function Main()
      DTSDestination("OrderNumber") = DTSSource("OrderNumber")
      DTSDestination("OrderDate") = DTSSource("OrderDate")
      DTSDestination("Customer") = DTSSource("Customer")
      DTSDestination("DocumentType") = DTSSource("DocumentType")
      DTSDestination("Project") = DTSSource("Project")
      DTSDestination("Rep_1") = DTSSource("Rep_1")
      DTSDestination("Rep_2") = DTSSource("Rep_2")
      Main = DTSTransformStat_OK
End Function
Start your free trial to view this solution
Question Stats
Zone: Microsoft
Question Asked By: bwbpro
Solution Provided By: cybeh
Participating Experts: 2
Solution Grade: A
Views: 312
Translate:
Loading Advertisement...
03.24.2007 at 07:22PM PDT, ID: 18787005

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.24.2007 at 08:24PM PDT, ID: 18787166

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.25.2007 at 01:10AM PDT, ID: 18787618

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.25.2007 at 08:47AM PDT, ID: 18788316

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.25.2007 at 02:16PM PDT, ID: 18789551

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.26.2007 at 04:56PM PDT, ID: 18796813

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.27.2007 at 10:09AM PDT, ID: 18801516

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.06.2007 at 07:49AM PDT, ID: 19432171

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.06.2007 at 08:56AM PDT, ID: 19432731

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
03.24.2007 at 07:22PM PDT, ID: 18787005
I am not sure if I do understand your problem. Have a look on this

    Columns("A:A").ColumnWidth = 13.14
    With Selection.Font
        .Name = "Arial"
        .Size = 12
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
    End With
    Selection.Font.Bold = True
    Selection.Font.ColorIndex = 3

 
03.24.2007 at 08:24PM PDT, ID: 18787166
Cybeh - I think you're on the right track with what I need.  I'm thinking the best way to accomplish this may be to run a scheduled vb script after the file is created from the DTS Package.  The problem is I don't know how to write the scipt (I'm just starting to read up on VB).  The script would have to call the existing file, run the formatting script and save/close it.  The best I can pull off at this point is to record the macro within Excel for the exact formatting I need.  The file name and location is D:\Automated Reports\BackOrderReport.xls.  I'll also attach the macro I recorded.  If you can help me turn this into a script I would be very grateful!  Brett

Here's the macro:

Sub Formatting()
    Rows("1:1").Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    With Selection.Font
        .Name = "Tahoma"
        .FontStyle = "Bold"
        .Size = 8
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
    End With
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone
    Selection.Borders(xlEdgeTop).LineStyle = xlNone
    Selection.Borders(xlEdgeBottom).LineStyle = xlNone
    Selection.Borders(xlEdgeRight).LineStyle = xlNone
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Columns("A:A").ColumnWidth = 10#
    Columns("A:A").ColumnWidth = 9.78
    Columns("B:B").EntireColumn.AutoFit
    Columns("C:C").EntireColumn.AutoFit
    Columns("D:D").EntireColumn.AutoFit
    Columns("E:E").ColumnWidth = 36.89
    Columns("H:H").ColumnWidth = 11.44
    Columns("I:I").ColumnWidth = 7.67
        With ActiveSheet.PageSetup
        .PrintTitleRows = "$1:$1"
        .PrintTitleColumns = ""
    End With
    ActiveSheet.PageSetup.PrintArea = ""
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = "Back Order Report"
        .RightHeader = ""
        .LeftFooter = ""
        .CenterFooter = "Page &P"
        .RightFooter = ""
        .LeftMargin = Application.InchesToPoints(0.5)
        .RightMargin = Application.InchesToPoints(0.5)
        .TopMargin = Application.InchesToPoints(0.75)
        .BottomMargin = Application.InchesToPoints(0.75)
        .HeaderMargin = Application.InchesToPoints(0.5)
        .FooterMargin = Application.InchesToPoints(0.5)
        .PrintHeadings = False
        .PrintGridlines = True
        .PrintComments = xlPrintNoComments
        .PrintQuality = 300
        .CenterHorizontally = True
        .CenterVertically = False
        .Orientation = xlLandscape
        .Draft = False
        .PaperSize = xlPaperLetter
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .BlackAndWhite = False
        .Zoom = 80
        .PrintErrors = xlPrintErrorsDisplayed
    End With
    ActiveWorkbook.Save
End Sub
 
03.25.2007 at 01:10AM PDT, ID: 18787618
I am not sure if I understand your problem. I guess you want sometime where you supply a file name, and the script will do the macro that you mention?

So, maybe it's something like
C:\myAutoScript.exe C:\myExcelFile.xls

then it will do the format to C:\myExcelFile.xls?

Please let me know if I am on the correct path.
 
03.25.2007 at 08:47AM PDT, ID: 18788316
Cybeh - Yes, that is what I'm looking for.  A script to execute and format my existing Excel file based on the macro I recorded above.  Just to give you an idea what I have set up right now; I have an IT guy that wrote a .bat that is scheduled to run a vbscript.  This script emails the file I've mentioned once per week. Unfortantely, the file is not formatted to be very readable or printable for the recipients.   The recipients are salespeople that are very technology challenged.  For the formatting, I thought we could possibly setup the same scenario to have .bat run a vbscript that formats this file as needed (see recorded macro in my previous message).  I would schedule this script to run before the email script (or add it to the existing email script).  Thus, the recipient receives a nice, clean excel file, they can print without having to do any formatting themselves.  Unfortunately, my IT guy is not familiar with scripting to format office docs.  I'm always open to another approach if you know of a simpler way to accomplish this.  Thanks again for taking a look at this!  Brett
 
03.25.2007 at 02:16PM PDT, ID: 18789551
I just give u some sample. You need to modify it base on your own macro.

Option Explicit
'Define the required variable
Dim Excel As Excel.Application ' This is the excel program
Dim ExcelWBk As Excel.Workbook ' This is the work book
Dim ExcelWS As Excel.Worksheet ' This is the sheet

Public Sub FormatThisFile(byval strFileName as string)
   Set Excel = GetObject(, "Excel.Application") ' Create Excel Object
   Set ExcelWBk = Excel.Workbooks.Open(strFileName)
   Set ExcelWS = ExcelWBk.Worksheets(1)
   Excel.Visible = False
   call Formatting
    Excel.Visible = True
    ExcelWBk.Close
    Excel.Quit
    Set ExcelWBk = Nothing
    Set Excel = Nothing
End Sub

Sub Formatting()
    With ExcelWS
        With .Range("1:1")
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .WrapText = True
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
            .Font.Name = "Tahoma"
            .Font.FontStyle = "Bold"
            .Font.Size = 8
            .Borders(xlDiagonalDown).LineStyle = xlNone
            .Borders(xlDiagonalUp).LineStyle = xlNone
            .Borders(xlEdgeLeft).LineStyle = xlNone
            .Borders(xlEdgeTop).LineStyle = xlNone
            .Borders(xlEdgeBottom).LineStyle = xlNone
            .Borders(xlEdgeRight).LineStyle = xlNone
            .Borders(xlInsideVertical).LineStyle = xlNone
        End with
       
        With .Range("A:A").ColumnWidth = 10#
       
       
    End with

End Sub
Accepted Solution
 
03.26.2007 at 04:56PM PDT, ID: 18796813

Rank: Wizard

Perhaps I am stating the obvious, but you do realize you will have to install MS Office on the same server as MS SQL Server, right?
 
03.27.2007 at 10:09AM PDT, ID: 18801516
Yep acperkins - I did make sure Office was installed, but I do understand you can never assume the obvious.

Cybeh - I'm having a tough time running the script you provided but that is probably because I'm a complete vbscript idiot (trying to progress to an idiot with enough knowledge to be dangerous).  When I run it the console opens an closes immediately without running anything.  Also wondering, if my existing file is D:\Automated Reports\BackOrderReport.xls, how would I incorporate that into your string?  Would it be as below?

Public Sub FormatThisFile(byval strFileName as string)
   Set Excel = GetObject(, "Excel.Application") ' Create Excel Object
   Set ExcelWBk = Excel.Workbooks.Open(D:\Automated Reports\BackOrderReport.xls)
   Set ExcelWS = ExcelWBk.Worksheets(1)
   Excel.Visible = False
   call Formatting
    Excel.Visible = True
    ExcelWBk.Close
    Excel.Quit
    Set ExcelWBk = Nothing
    Set Excel = Nothing
End Sub

I'm thinking not since I tried it and it didn't work.  Can you help me out with what I may be missing?

Sorry if these are a dumb questions but I'm trying.  I just have a lot to learn.
Thanks again!
Brett


 
07.06.2007 at 07:49AM PDT, ID: 19432171
Cybeh - Thanks for all of your help.  I'm am now on SQL 52005 and Reporting Services but your help with SQL 2000 and DTS was very valuable...Brett
 
07.06.2007 at 08:56AM PDT, ID: 19432731
Glad to help.
 
 
20080236-EE-VQP-29