Solved

Convert Excel macro to VBScript

Posted on 2013-01-20
4
924 Views
Last Modified: 2013-01-20
I'm trying to format excel from VBS  - I'm grouping several columns and it works fine but I need to collapse the column level. The last line (in bold) was recorded using the macro recorder. My question is: how do I translate this so it will run in VBS (how do I collapse the outline in VBS)?

Set myExcel = CreateObject("Excel.Application")
myExcel.visible = TRUE
Set myWorkbook=myExcel.Workbooks.Open("C:\Scripts\10_Macro_Format.xlsx")
Set mySheet = myWorkbook.sheets(1)
mySheet.Range("C1:H1").Group

ActiveSheet.Outline.ShowLevels RowLevels:=0, ColumnLevels:=1
0
Comment
Question by:mike_VBS
[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
  • 2
  • 2
4 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 38799228
Try this:

Dim myExcel, myWorkbook, mySheet

Set myExcel = CreateObject("Excel.Application")
myExcel.visible = TRUE
Set myWorkbook=myExcel.Workbooks.Open("C:\Scripts\10_Macro_Format.xlsx")
Set mySheet = myWorkbook.sheets(1)

With mySheet
    .Range("C1:H1").Group
    .Outline.ShowLevels RowLevels:=0, ColumnLevels:=1
End With

Open in new window

0
 

Author Comment

by:mike_VBS
ID: 38799333
get the following error on line 10

Microsoft VBScript compilation error: Expected statement
0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 38799395
Sorry, forgot that VBScript does not support passing arguments by name.

Dim myExcel, myWorkbook, mySheet

Set myExcel = CreateObject("Excel.Application")
myExcel.visible = TRUE
Set myWorkbook=myExcel.Workbooks.Open("C:\Scripts\10_Macro_Format.xlsx")
Set mySheet = myWorkbook.sheets(1)

With mySheet
    .Range("C1:H1").Group
    .Outline.ShowLevels 0, 1
End With

Open in new window

0
 

Author Comment

by:mike_VBS
ID: 38799413
Yes, that works - hacking around a could have sworn I tried that - I guess not.

Hey, thanks!
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

739 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