Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Set Variables Here
- strSheetName = "Sheet1" 'Name of the spreadsheet inside the Excel file to work in
- strDeliminationSym = "|" 'Character that will split the input string
- '===============================================================================================================
- Function OpenFileDialog(sDir, sFilter, sTitle)
- With Createobject("Scripting.FileSystemObject")
- If .FileExists("OUTPUT") Then .DeleteFile("OUTPUT")
- CreateObject("WScript.Shell").Run _
- "powershell.exe -command ""& {"& _
- "[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | Out-Null;"& _
- "$o = New-Object System.Windows.Forms.OpenFileDialog;"& _
- "$o.InitialDirectory = '"& sDir &"';"& _
- "$o.Filter = '"& sFilter &"';"& _
- "$o.Title = '"& sTitle &"';"& _
- "$o.ShowDialog() | Out-Null;"& _
- "$o.filename > OUTPUT"& _
- "}""",0
- Do
- WScript.Sleep 100
- Loop While Not .FileExists("OUTPUT")
- With .OpenTextFile("OUTPUT", 1, False, -1)
- Do While .AtEndOfStream
- WScript.Sleep 100
- Loop
- OpenFileDialog = .ReadLine
- End With
- .DeleteFile("OUTPUT")
- End With
- End Function
- ExcelFile = OpenFileDialog("", "Excel Files|*.xlsx;*xls", "Select an Excel document")
- If Len(ExcelFile) = 0 Then
- MsgBox "You need to select an Excel document."
- WScript.Quit
- End If
- Set obj = createobject("Excel.Application")
- obj.visible=True
- Set obj1 = obj.Workbooks.open(ExcelFile)
- Set obj2 = obj1.Worksheets(strSheetName)
- Found = False
- whileCount = 1
- Do While Found = False
- rowResult = obj2.Cells(whileCount,1).Value
- whileCount = whileCount + 1
- if Len(rowResult) = 0 Then
- Found = True
- whileCount = whileCount - 2
- End If
- Loop
- for x = 1 to whileCount
- strInput = obj2.Cells(x,1).Value
- arrContent = Split(strInput, strDeliminationSym)
- for i = 1 to UBound(arrContent)
- obj2.Cells(x,i).Value = arrContent(i)
- Next
- Next
- obj1.Close
- obj.Quit
- Set obj1=Nothing
- Set obj2=Nothing
- Set obj=Nothing
- Set Found = Nothing
- Set whileCount = Nothing
- Set x = Nothing
- Set i = Nothing
- Set arrContent = Nothing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement