Problems open workbook via macro

K

kalle

Hi

I have a problem with the code below.
The macro search for the latest version of a file and then open it and
close itsef.

If I open the file containing this macro in the usual way it works as it
should.

But if I open it via a hyperlink doese't work.

The macro runs with no error but only the file with the hyperlink is
shown.
Någon som vet vad som är fel och vill hjälpa mig?

Thanks in advance

Private Sub Workbook_Open()
Dim FSO As Scripting.FileSystemObject
Dim SourceFolder As Scripting.Folder
Dim FileItem As Scripting.File
Dim Version As Integer
Dim Temp as Integer
Dim CurrentFile As String
Dim Projekt_Folder As String

Projekt_Folder = "folder"

Set FSO = New Scripting.FileSystemObject
Set SourceFolder = FSO.GetFolder(Projekt_Folder)
For Each FileItem In SourceFolder.Files
If Right(UCase(FileItem.Name), 4) = ".XLS" And
Left(FileItem.Name, 10) = "abcdefgh.v" Then
If Not IsNumeric(Left(Right(FileItem.Name, 6), 2)) Then GoTo
NotANumber
Temp = Left(Right(FileItem.Name, 6), 2)
If Temp > Version Then
Version = Temp
CurrentFile = FileItem.Name
End If
NotANumber:
On Error GoTo 0

End If
Next FileItem
Set FileItem = Nothing
Set SourceFolder = Nothing
Set FSO = Nothing
On Error Resume Next
Workbooks.Open Projekt_Folder & CurrentFile, , True

ThisWorkbook.Close False
End Sub

*** Sent via Developersdex http://www.developersdex.com ***
 
J

joel

try opening a new application

From

Workbooks.Open Projekt_Folder & CurrentFile, , True


To

Dim NewApp As Excel.Application
Set NewApp = CreateObject("Excel.application")
NewApp.Workbooks.Open Filename:=Projekt_Folder & CurrentFile
ThisWorkbook.Close savechanges:=False
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top