[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

5.8

Problem opening Excel from VB and importing a data file.

Asked by nmattern in Visual Basic Programming

Tags: excel

I created a VB 6 application (below is the code for the two buttons that I use).

The first button works 100% correctly.  The second one opens Excel, but then illegal operations' out.

Any ideas why this wouldn't work?  I took the Excel (VBA) code from a macro I wrote to do the import functions.

-------------------------------------
Option Explicit

Private Sub Command1_Click()

'Register DLL's
'VBRegSvr32 "C:\fpexport\#Filename.ext#"

' Sets the Dialog Title to Open File
CommonDialog1.DialogTitle = "Open File"

' Sets the File List box to Word documents and Excel documents
CommonDialog1.Filter = "Text Files (*.dat)|*.dat"

' Set the default files type to Word Documents
CommonDialog1.FilterIndex = 1

' Sets the flags - File must exist and Hide Read only
CommonDialog1.Flags = cdlOFNFileMustExist + cdlOFNHideReadOnly

' Set dialog box so an error occurs if the dialogbox is cancelled
CommonDialog1.CancelError = True

' Enables error handling to catch cancel error
On Error Resume Next
' display the dialog box
CommonDialog1.ShowOpen
If Err Then
    ' This code runs if the dialog was cancelled
    MsgBox "Dialog Cancelled"
    Exit Sub
End If

lblFileStatus.Caption = "File Selected: " & CommonDialog1.FileName

End Sub

Private Sub Command2_Click()

    Dim appXl As Excel.Application
    Dim wrkFile As Workbooks
   
    ' Set object variables.
    Set appXl = New Excel.Application
    Set wrkFile = appXl.Workbooks

    ' Open a file.
    On Error Resume Next
    Set appXl = GetObject(, "Excel.Application")
       If appXl Is Nothing Then Set appXl = New Excel.Application

    ' Display Excel.
    appXl.Visible = True
       
    If Err.Number <> 0 Then
        MsgBox Err.Description & vbCrLf & Err.Number
    End If
   
    'Import the .DAT file to excel and bypass the 'import wizard'.
    'Workbooks.OpenText instead of wrkFile.

'********************
    'THIS IS WHERE THE PROBLEM BEGINS....


    wrkFile.OpenText FileName:=CommonDialog1.FileName, Origin:=437, _
        StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
        ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False _
        , Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), _
        Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 1), _
        Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15, 1), Array( _
        16, 1), Array(17, 1)), TrailingMinusNumbers:=True
       
    If Err.Number <> 0 Then
        MsgBox Err.Description & vbCrLf & Err.Number
    End If
           
    'Autofit the table
    Cells.Select
    Cells.EntireColumn.AutoFit
    Range("A1").Select
   
    'Format Columns O through Q as Currency
    Columns("O:Q").Select
    Selection.NumberFormat = "$#,##0.00"
   
    'Go to A1
    Range("A1").Select
   
    'Find and format the bottom items.
    Cells.Find(What:="TOTAL COMMISSION", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate
    ActiveCell.Offset(1, 0).Range("A1:B14").Select
    Selection.Style = "Currency"
    Range("A1").Select

If Err.Number <> 0 Then
    MsgBox Err.Description
End If

' Sets the Dialog Title to Save File
CommonDialog1.DialogTitle = "Save File"

' Sets the File List box to Text File and All Files
CommonDialog1.Filter = "Excel Files (*.xls)|*.xls"

' Set the default files type to Text File
CommonDialog1.FilterIndex = 1

' Sets the flags - Hide Read only, prompt to overwrite, and path must exist
CommonDialog1.Flags = cdlOFNHideReadOnly + cdlOFNOverwritePrompt _
+ cdlOFNPathMustExist

' Set dialog box so an error occurs if the dialogbox is cancelled
CommonDialog1.CancelError = True

Form1.Show
CommonDialog1.ShowSave

   
End Sub


Private Sub Command4_Click()
End
End Sub




 
 
[+][-]10/21/03 03:16 PM, ID: 9594572Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Visual Basic Programming
Tags: excel
Sign Up Now!
Solution Provided By: Computer101
Participating Experts: 6
Solution Grade: A
 
[+][-]07/02/03 11:26 AM, ID: 8842784Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/02/03 11:38 AM, ID: 8842887Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/02/03 11:57 AM, ID: 8843046Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/02/03 12:14 PM, ID: 8843175Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/02/03 12:18 PM, ID: 8843204Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/02/03 12:19 PM, ID: 8843214Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/02/03 12:44 PM, ID: 8843407Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/02/03 12:50 PM, ID: 8843451Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/02/03 01:08 PM, ID: 8843599Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/02/03 05:08 PM, ID: 8845078Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/03/03 06:07 AM, ID: 8848929Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/03/03 04:53 PM, ID: 8853467Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/03/03 05:00 PM, ID: 8853497Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/02/03 03:16 PM, ID: 9270601Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/02/03 03:25 PM, ID: 9270659Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/03/03 05:47 AM, ID: 9275587Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/03/03 06:10 AM, ID: 9275908Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/03/03 07:26 PM, ID: 9284628Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/14/03 05:39 PM, ID: 9551291Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/15/03 05:55 AM, ID: 9554254Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92