Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Aug 2001
    Location
    NY, NY, USA
    Posts
    654
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Visual Basic file close / file open problem (Office XP sp2)

    I have the following macro which closes out the current file and loads a new file. It works fine unless there is no file to close. How do I adjust for this possiblilty
    Public Sub MAIN()
    WordBasic.FileClose 2
    WordBasic.FileOpen Name:=" c:msofficewinwordGENCNSNT.DOC", ConfirmConversions:=0, ReadOnly:=0, AddToMru:=0, PasswordDoc:="", PasswordDot:="", Revert:=0, WritePasswordDoc:="", WritePasswordDot:=""
    End Sub
    Thanks
    Jerome

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Visual Basic file close / file open problem (Office XP sp2)

    Hi Jerome,

    The code you post is WordBasic code. Starting with Word 97, WordBasic has been succeeded by Visual Basic for Applications (VBA), although the WordBasic object is still supported. Naming a procedure MAIN is a relic from WordBasic; in VBA you can give a procedure any name; a module can contain many macros (= procedures without arguments), each can be called by its indivudual name.

    Here is a Word VBA equivalent of your macro, with a check to avoid an error if there is no document open:

    Sub MyMacro()
    If Documents.Count > 0 Then
    ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
    ' You can also use wdSaveChanges or wdPromptToSaveChanges
    End If
    Documents.Open FileName:="C:MSOfficeWinwordGENCNSNT.DOC", ConfirmConversions:=False, _
    AddToRecentFiles:=False, Revert:=False
    End Sub

  3. #3
    5 Star Lounger
    Join Date
    Aug 2001
    Location
    NY, NY, USA
    Posts
    654
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Re: Visual Basic file close / file open problem (Office XP sp2)

    Many many thanks, this must be real relic code. Just drove me crazy
    The fix is really great
    Thanks
    Jerome

Posting Permissions

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