• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

VB6 Batch-type file?

Is there a way to make an EXE in VB6 that is similar to a DOS batch file?

I have a few different DOC files that I want to open all at once, but the batch file I made will only open one at a time (open file1, close file1 and open file2, etc.).

If it's possible to do, can you point me in the right direction, please? Thanks guys, and girls!
  • 4
  • 3
1 Solution
Mike TomlinsonMiddle School Assistant TeacherCommented:
Here is a generic function to open a word document:

OpenDoc "c:\my documents\address labels.doc"

Private Function OpenDoc(fileName As String)
    Me.MousePointer = vbHourglass
    Dim MSWordApp, MSWordDoc As Object
    On Error Resume Next
    Set MSWordApp = GetObject(, "Word.Application")
    If Err.Number <> 0 Then
        Set MSWordApp = CreateObject("Word.Application")
    End If
    Set MSWordDoc = MSWordApp.Documents.Open(fileName)
    MSWordApp.WindowState = 1
    Set MSWordDoc = Nothing
    Set MSWordApp = Nothing
    Me.MousePointer = vbDefault
End Function
JFryeAuthor Commented:
Ok, and one more question: For this EXE, if the DOCs are in the same folder as the EXE, can I just put "file1.doc" or will I need "c:\files\galore\file1.doc"?
Mike TomlinsonMiddle School Assistant TeacherCommented:
You can use:

OpenDoc App.Path & "\file1.doc"
Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

JFryeAuthor Commented:
Well, that didn't work. It seems that the file is opened, however Word never opens to actually view the files.
Mike TomlinsonMiddle School Assistant TeacherCommented:
Try adding

MSWordApp.Visible = 1


MSWordApp.WindowState =  1

The code worked great on my system as is.
JFryeAuthor Commented:
Fantastic! Kudos and 50 points for you!!!
Mike TomlinsonMiddle School Assistant TeacherCommented:
Glad it worked.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now