CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2001
    Posts
    34

    Saving an excel file as a txt file using active X

    I am writing a program that must do the following...........

    1. Open an excel file (.xls)
    2. Amend the file
    3. Save the file as a tabbed text file


    At present (using activex) steps 1 nd 2 work corectly, and i can save as a .xls document but the problem lies in the file format (it must be a tabbed text file , I have tried difrent ways of specifying this format but with little success could you please have a look at my program and sugest what code to use.

    if i can do this without the save as dialogue box apearing then that will perfect.

    Can anyone help?



    -DAVE

  2. #2
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: Saving an excel file as a txt file using active X

    Post your code briefly so that we can take a look at what you're doing right now

    -Cool Bizs

    Good Luck,
    -Cool Bizs

  3. #3
    Join Date
    May 2001
    Posts
    34

    Re: Saving an excel file as a txt file using active X

    This is the main module at present................




    Option Explicit
    Dim obexcel As Object


















    Public Sub OpenExcelFile(strpath As String)
    Dim strfilename As String
    strfilename = (strpath)

    Set obexcel = CreateObject("Excel.Application")


    obexcel.workbooks.open strfilename
    obexcel.Visible = True
    MsgBox "Excel Application Open"

    End Sub

    Public Sub Amend()
    Set obworksheet = obexcel.activesheet

    obworksheet.cells(1, 1).Value = "sales"
    End Sub


    Public Sub SaveExcelFile(strpath As String, strformat As String)
    Dim strfilename As String
    Dim strfileformat As String

    strfileformat = (strformat)
    strfilename = (strpath)


    Dim blnrunning As Boolean

    'Set obexcel = GetObject(, "Excel.Application")
    'Set obexcelbasic = GetObject(, "Excel")

    'If Err.Number <> 0 Then
    ' Set obexcel = CreateObject("Excel.Application")

    ' blnrunning = False
    'Else
    ' blnrunning = True
    'End If
    'Set obopensheet = CreateObject("Excel.Worksheet")
    'Set obworksheet = obexcel.activesheet
    'Set obexcelbasic = CreateObject("Excel")
    'obexcelbasic.worksheet.SaveAs "c:\4.txt", "xltext") = True
    'obexcel.activeworkbook.SaveAs strfilename, strfileformat
    'obexcel.activeworkbook.Close False

    obexcel.Run.macrosa (strfilename)

    If Not (blnrunning) Then
    obexcel.Quit
    End If

    End Sub


    As you will notice the savexcelfile sub is a bit messed up this is due to experimentaion.

    Thanx

    -DAVE

  4. #4
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: Saving an excel file as a txt file using active X

    I think you've the answer for this already on another forum thread:
    http://www.codeguru.com/cgi-bin/bbs/...collapsed&sb=5

    -Cool Bizs

    Good Luck,
    -Cool Bizs

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured