![]() |
Problems open workbook via macro
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 *** |
Problems open workbook via macro
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 -- joel ------------------------------------------------------------------------ joel's Profile: 229 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=181710 Microsoft Office Help |
All times are GMT +1. The time now is 11:15 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com