Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-07-2012, 02:27 PM
jeffcoleky jeffcoleky is offline Macro: Exporting Data to a LEGIBLE Excel Spreadsheet Windows 7 64bit Macro: Exporting Data to a LEGIBLE Excel Spreadsheet Office 2010 32bit
Novice
Macro: Exporting Data to a LEGIBLE Excel Spreadsheet
 
Join Date: May 2012
Posts: 4
jeffcoleky is on a distinguished road
Default


This worked (got help from another website

Code:
Sub Export2XL()
    Dim app As Object
    Dim wbk As Object
    Dim wsh As Object
    Dim r As Long
    Dim p As Long
    Dim n As Long
    Dim i As Long
    Dim arr As Variant
    Dim strLine As String
    ' Start Excel
    On Error Resume Next
    Set app = GetObject(Class:="Excel.Application")
    If app Is Nothing Then
        Set app = CreateObject(Class:="Excel.Application")
        If app Is Nothing Then
            MsgBox "Can't start Excel!", vbExclamation
            Exit Sub
        End If
    End If
    On Error GoTo ErrHandler
    ' Create workbook with one worksheet
    app.ScreenUpdating = False
    Set wbk = app.Workbooks.Add(Template:=-4167) ' xlWBATWorksheet
    Set wsh = wbk.Worksheets(1)
    r = 1
    wsh.Cells(r, 1) = "PTF"
    wsh.Cells(r, 2) = "DEF"
    wsh.Cells(r, 3) = "PURCHASER"
    wsh.Cells(r, 4) = "ADDRESS"
    wsh.Cells(r, 5) = "AMOUNT"
    ' Date
    strLine = ActiveDocument.Paragraphs(1).Range.Text
    p = InStr(strLine, vbTab)
    strLine = Mid(strLine, p + 1, Len(strLine) - p)
    wsh.Name = strLine
    ' Loop
    n = ActiveDocument.Paragraphs.Count
    For i = 2 To n
        strLine = ActiveDocument.Paragraphs(i).Range.Text
        strLine = Left(strLine, Len(strLine) - 1)
        arr = Split(strLine, vbTab)
        ' Determine type
        If arr(2) = "PTF" Then
            r = r + 1
            wsh.Cells(r, 1) = arr(3)
        ElseIf arr(1) = "DEF" Then
            wsh.Cells(r, 2) = arr(2)
        ElseIf arr(1) = "COUNT" And UBound(arr) >= 3 Then
            wsh.Cells(r, 3) = arr(3)
        ElseIf arr(1) = "ADDRESS" Then
            wsh.Cells(r, 4) = arr(2)
            wsh.Cells(r, 5) = arr(4)
        Else
            ' Footer - ignore
        End If
    Next i
ExitHandler:
    If Not app Is Nothing Then
        wsh.Range("A1:E1").EntireColumn.AutoFit
        app.ScreenUpdating = True
        app.Visible = True
    End If
    Exit Sub
ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
End Sub
Reply With Quote
Reply

Tags
exporting to exel



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro: Exporting Data to a LEGIBLE Excel Spreadsheet * Exporting Access Data to Excel djreyrey Excel Programming 1 03-23-2012 10:03 PM
Macro: Exporting Data to a LEGIBLE Excel Spreadsheet Importing data from excel using a macro soma104 Word 1 04-14-2011 05:10 PM
Exporting Timline Milstone Data OTPM Project 0 04-06-2011 02:34 AM
Macro: Exporting Data to a LEGIBLE Excel Spreadsheet Exporting PST data metfuel Outlook 2 01-19-2011 04:46 PM
Macro: Exporting Data to a LEGIBLE Excel Spreadsheet Exporting data dsmithers Outlook 2 06-24-2009 09:58 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:11 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft