12. august 2005 - 10:58Der er
16 kommentarer og 1 løsning
Hvorfor åbner den ikke filen?
Hej
JEg har lavet denne lille stump kode:
With Dialogs(wdDialogFileFind) .SearchPath = "p:\test" .title = title .Display End With
Hvor dialogboksen Abn godt nok åbnes med de rigtige søgekriterier, men når jeg så markerer en fil og klikker ÅBN, så sker der ikke noget (den åbner simpelthen ikke filen.
Nogen forslag til hvordan jeg får den til at åbne den fil jeg måtte vælge?
Teknologi, AI og forretning er i centrum på Computerworlds Cloud og AI Festival i København d. 18. og 19. september. Se hele programmet for den store konference om strategisk brug af Cloud og AI på: www.cloud-festival.dk
Nej, jeg vil finde alle filer på placeringen p:\test hvor der står title i feltet titel. Det finder den også helt fint, men når jeg så markerer en af filerne og klikker åbn (eller sobbeltklikker på en) så åbner den ikke filen??
Function FindFiles(Optional ByVal strPath As String, Optional ByVal strExtension As String) As String
Dim dlg As Dialog Dim dlgFind As Dialog Dim strFile As String Dim strDefaultOpenPath As String
'Get and hang onto the user's default document path strDefaultOpenPath = _ Application.Options.DefaultFilePath(wdDocumentsPath)
'Evaluate the passed variables to see 'if we need to give them a value If strPath = "" Then 'No argument was passed so... 'Point to default document path strPath = strDefaultOpenPath End If
If strExtension = "" Then 'No argument was passed so... 'Point to default Word Document File Type strExtension = "*.doc" End If
'Set the SearchPath Application.Options.DefaultFilePath(wdDocumentsPath) = strPath
'display common dialog Set dlg = Dialogs(wdDialogFileOpen) Set dlgFind = Dialogs(wdDialogFileFind) With dlg .Name = strExtension 'Did they press Cancel? If so, exit the routine Select Case .Display Case -1 'Update the FileFind Dialog dlgFind.Update strPath = dlgFind.SearchPath strFile = dlg.Name Case Else 'Restore the defautl Doc Path Application.Options.DefaultFilePath(wdDocumentsPath) = strDefaultOpenPath Exit Function End Select End With
'Update our variable with info from the Dialogs strFile = dlg.Name
'Ensure that the returned path is appropriately padded 'with a separator like \ or :, depending on your system type If Right(strPath, 1) <> Application.PathSeparator Then strPath = strPath & Application.PathSeparator End If
'concatentate an explicit path-file string strFile = strPath & strFile
'Restore User settings Application.Options.DefaultFilePath(wdDocumentsPath) = strDefaultOpenPath
JEg har brug for at kunne identificere et dokument (flere dokumenter naturligvis) ved hjælp af to oplysninger der indtastes i en dialogboks. Den ene indtastning bliver til filnavnet når dokumentet gemmes og vil altid være entydig, hvorimod den anden vil kunne figurere i flere dokumenter.
Man skal så kunne finde frem til alle filer der indeholder den anden oplysning.
Her er et groft udkast til en makro, der finder de filer der har titlen "Test". resultatet kunne sættes ind i en listboks, som brugeren kan vælge filen fra, hvorefter den åbnes:
Sub GetFileList()
Dim oSearch As FileSearch
' Change strDirName to the path of the directory for which you want a ' listing. Dim strDirName As String Dim strPrompt As String
' Get a reference to the FileSearch object. Set oSearch = Application.FileSearch
With oSearch
' Reset the search. .NewSearch
' Specify the directory that contains the files you want to count. ' The variable strDirName is the parameter of the CountAllFiles() ' function. .LookIn = strDirName
' Exclude subfolders. .SearchSubFolders = False
' Specify what types of files you want to find. ' For example, to search for text files change this line to: ' .FileName "*.txt" .FileName = "*.*"
' The Execute command begins the search. .Execute
' Check to see if any files were found. If .FoundFiles.Count > 0 Then
' Loop through the files that were found and store the file names ' in the variable strPrompt. For i = 1 To .FoundFiles.Count
On Error Resume Next Dim FileName As String Dim DSO As DSOleFile.PropertyReader Set DSO = New DSOleFile.PropertyReader FileName = .FoundFiles(i)
If Err Then
Err.Clear Else With DSO.GetDocumentProperties(sfilename:=FileName) titel = .Title End With
If titel = "Test" Then strPrompt = strPrompt & .FoundFiles(i) & Chr(13) End If End If Next i Else strPrompt = strPrompt & "No files found." End If
' Display the file list in a message box. MsgBox strPrompt
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.