1

I like to export 2 columns from a .xls file to a txt.

Let say column C and D. Im also trying to seperate them with a _. The .xls have several sheets and I only need data from one of them. How do you accoplish that?

This is what I have so far. I have never done anything like this before and I honestly dont know what I am doing rihgt/wrong. I get all kinds or errors and haveing a hard time figure vbs out.

Dim saveDir
set fso = CreateObject("Scripting.FileSystemObject")
set shell = CreateObject("WScript.Shell")
set objExcel = CreateObject("Excel.Application")
Set objArgs = WScript.Arguments
Set fso = CreateObject("Scripting.FileSystemObject")

set top = fso.GetFolder(shell.CurrentDirectory)
DirBase = top & "\" & "jipCOPY" & "\"

    Set objExcel = CreateObject("Excel.application")
    set objExcelBook = objExcel.Workbooks.Open(DirBase & "1.xls")
    objExcel.application.visible=false
    objExcel.application.displayalerts=false

    Set puCols = objExcel.Range("C13","C15")
    Set poCols = objExcel.Range("D13","D15")

 Const ForWriting = 2
 Set objFSO = CreateObject("Scripting.FileSystemObject")
 Set objFile = objFSO.OpenTextFile("jipDATA.txt", ForWriting)
 objFile.WriteLine puCols & "_" & poCols
 objFile.Close 


    objExcel.Application.Quit
    objExcel.Quit   
    Set objExcel = Nothing
    set objExcelBook = Nothing

I'm trying to do this with a .vbs executed from a .bat.

All code is taken from this site and I tried to mod it but I cant say that it is going the right direction. Any one who could help out a bit, point me in the right direction or any thing?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Moberg
  • 33
  • 5

1 Answers1

0

Your best bet is to learn how to debug. That will let you deal with each of your "all kinds or errors", or at least post which line produces each error (and specify it). Otherwise, you are bound to waiting for someone to fix the code for you, it might be unlikely.

Check How do I debug a stand-alone VBScript script? . There are plenty of other sources. Essential tips:

  • Place breakpoints.
  • Execute step by step
  • Inspect values of variables, with Debug.Print (in your code and in the immediate window), with Watches, etc.
Community
  • 1
  • 1