LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Junior Member
 
Posts: 1
Default ExportToExcel Macro

Hi, I have a macro I use in AttachmateWRQ, Reflections. The macro is supposed to take the text I highlighted and ask me what delimiter I want to use, then export it into Excel. It's not working...I'm getting an error (attached). This VB code works in Visual Studio but not in Reflections. Any thoughts? I am using Excel 2007 and AttachmateWRQ Version 14.0.

Thanks in advance!!


' DESCRIPTION: Prompts for a delimiter, launches Excel, and uses the delimiter to parse highlighted sText into individual columns


Sub ExportToExcel()
On Error GoTo ErrorHandler
Dim appExcel As Excel.Application
Dim wkb As Excel.Workbook
Dim wks As Excel.Worksheet
Dim sDelimiter As String
Dim sText As String
Dim Selection As VbMsgBoxResult

sDelimiter = InputBox("Enter the delimiter you'd like to use.", "Enter Delimiter", "^")

If Len(sDelimiter) 0 Then
Copy (rcSelection)
sText = GetClipboardText()
Else
Exit Sub
End If

If Not Len(sText) 0 Then
MsgBox ("Please select text you'd like to export to Excel before using this macro.")
Exit Sub
End If

Selection = MsgBox("Format for column headers?", vbYesNo, "Special Formatting")

'Open and activate Excel workbook
Set appExcel = CreateObject("Excel.Application")
appExcel.Workbooks.Add
Set wkb = appExcel.ActiveWorkbook
Set wks = wkb.Sheets(1)

wks.Activate
appExcel.Application.Visible = True
wks.Paste

Set objRange = wks.Range("A1").EntireColumn
objRange.TextToColumns Destination:=wks.Range("A1"), DataType:=xlDelimited, Other:=True, OtherChar:=sDelimiter

If Selection = vbYes Then '*MB 04/12 - Additionally format if Yes
With appExcel
'Freeze top row
.ActiveWindow.SplitColumn = 0
.ActiveWindow.SplitRow = 1
.ActiveWindow.FreezePanes = True

'Bold column headers
.Rows(1).Font.Bold = True

'Select all cells
.Cells.HorizontalAlignment = xlLeft
.Cells.VerticalAlignment = xlBottom
.Cells.WrapText = False
.Cells.Orientation = 0
.Cells.AddIndent = False
.Cells.IndentLevel = 0
.Cells.ShrinkToFit = False
.Cells.ReadingOrder = xlContext
.Cells.MergeCells = False
.Cells.AutoFilter
.Cells.EntireColumn.AutoFit

'Finish by selecting top-left cell
.Cells(1, 1).Select
End With
End If

ErrorHandler:
Set appExcel = Nothing
Set wkb = Nothing
Set wks = Nothing
Set objRange = Nothing
End Sub
Attached Images
  
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro recorded... tabs & file names changed, macro hangs Steve Excel Worksheet Functions 3 October 30th 09 11:41 AM
AutoRun Macro with a delay to give user the choice to cancel the macro wanderlust Excel Programming 2 September 28th 07 04:09 PM
how to count/sum by function/macro to get the number of record to do copy/paste in macro tango Excel Programming 1 October 15th 04 01:16 PM
macro to delete entire rows when column A is blank ...a quick macro vikram Excel Programming 4 May 3rd 04 08:45 PM
Start Macro / Stop Macro / Restart Macro Pete[_13_] Excel Programming 2 November 21st 03 05:04 PM


All times are GMT +1. The time now is 02:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"