Re: Does anyone know how to write VB?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Larry Serflaten (serflaten_at_usinternet.com)
Date: 04/06/04


Date: Tue, 6 Apr 2004 10:33:29 -0500


"Eric" <email@anon.com> wrote
> Requirement: VB Program to call external program. External program is
> PDF995 which creates a .pdf output file. The output file may not appear
> right away. Following the call, the VB program must rename the output file.
> PDF995 holds the output file open until it is finished writing. The file
> cannot be renamed until it is closed. VB apparently cannot sit and wait on
> the calling statement.

What is not obvious is why the PDF995 program does not save the file to
the proper name to begin with. Have you fully researched that option?

Does PDF995 close down when it has saved the file, or is that left running?
If it closes down, then the Shell and Wait method should do as you need.

But, rather than force VB to wait in a tight loop, I would suggest using a timer.
While your program is in a tight loop, the CPU meter goes to the top and the
whole program becomes unresponsive to user input.

Not so when you use a timer. It fires an event ever so often, and in between
events your program is free to do other things, like accept user input.

For an example, add a timer to a new form, and paste in the code below.
Set the path to something that will work on your system then start the
program. It will wait for the file to be created, and then rename it. While
it waits you are free to move the form around, and minimize it if you want.
Go to the path folder and create the file, then watch the forms caption to
see that it finishes, and refresh Explorer to see the new name.

HTH
LFS

Option Explicit

Const Path = "D:\temp\"
Const File = "RenameThis.txt"

Private Sub Form_Load()
  ' Kick off PDF995 and start timer
  Timer1.Interval = 2000
  Timer1.Enabled = True
  Caption = "Waiting"
End Sub

Private Sub Timer1_Timer()

  If FileExists(Path & File) Then
    ' Rename it
    Name Path & File As Path & "Renamed.txt"
    Timer1.Enabled = False
    Caption = "Done"
  End If

End Sub

Private Function FileExists(ByRef FileName As String) As Boolean

  On Error Resume Next
  FileExists = ((GetAttr(FileName) And vbDirectory) <> vbDirectory)
  Err.Clear

End Function



Relevant Pages

  • Re: Automating Worksheet Names
    ... and rename the tab with the same value and insert,,..and so on after ... the tab name. ... on error goto 0 ... Private Sub Workbook_SheetCalculate ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Code issue - before_save() - Filename with date stamp - worksh
    ... Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, ... You really want characters {Filename} or to start ... Now the worksheet rename works, however the filename portion bombs out and I ...
    (microsoft.public.excel.programming)
  • Re: error when using FileCopy
    ... > an output file, and then is supposed to replace the input file with the new ... So I tried using Rename to do that, ... > Rename didn't exist as a function, and so I tried FileCopy. ... FileCopy outName, inName ...
    (microsoft.public.vb.general.discussion)
  • Re: Newbie: Works when stepped through, but not when run?
    ... > I have a simple code to rename the files in a specific folder. ... > Private Sub Command1_Click ... > Dim objFolder As Object ...
    (microsoft.public.vb.general.discussion)
  • Re: Locking down a tab
    ... Are you trying to stop the tab being renamed? ... Private Sub Worksheet_Deactivate ... and rename it. ... I know you can pass protect a spreadsheet but does anyone know a way I ...
    (microsoft.public.excel.misc)