01. marts 2001 - 12:37Der er
3 kommentarer og 1 løsning
Access VBA
Her er noget for eksperten. Jeg har i en formular en textbox, hvor brugeren skal indtaste stien til e´t excel regneark. Jeg har lavet flg kode for at lette indtastningen: Private Sub txtExcel_Adr_DblClick(Cancel As Integer) txtExcel_Adr.Value = Excel_Sti End Sub Function Excel_Sti() As String
Dim fil As String, sti As String Dim app As New Excel.Application
app.Dialogs.Item(xlDialogOpen).Show
fil = app.Workbooks.Item(1).Name sti = app.Workbooks.Item(1).Path Excel_Sti = sti & \"\\\" & fil \'MsgBox Excel_Sti
app.Workbooks.Close Set app = Nothing
End Function Jeg åbner altså et regneark vha excel dialogbox. Kan det ikke laves uden at åbne excel, det kan nemlig give fejl hvis man har et andet regneark åbent på samme tid. Nogen gode ideer ?????
Private Type OPENFILENAME lStructSize As Long hwndOwner As Long hInstance As Long lpstrFilter As String lpstrCustomFilter As String nMaxCustFilter As Long nFilterIndex As Long lpstrFile As String nMaxFile As Long lpstrFileTitle As String nMaxFileTitle As Long lpstrInitialDir As String lpstrTitle As String Flags As Long nFileOffset As Integer nFileExtension As Integer lpstrDefExt As String lCustData As Long lpfnHook As Long lpTemplateName As String End Type
Declare Function GetOpenFileName Lib \"comdlg32.dll\" Alias \"GetOpenFileNameA\" (pOpenfilename As OPENFILENAME) As Long
Function SelectExcelDoc() As String \' Opens the Open dialog with default values.
Dim msaof As OPENFILENAME Dim intRet As Integer Dim strRet As String \'initialize sensible fields of OPENFILENAME With msaof .lStructSize = Len(msaof) .lpstrTitle = \"Select Excel File\" .lpstrFilter = \"Excel Files\" & vbNullChar & \"*.xl*\" & vbNullChar & vbNullChar .lpstrFile = String$(255, 0) .nMaxFile = 255 End With
intRet = GetOpenFileName(msaof) If intRet Then strRet = Mid(msaof.lpstrFile, 1, InStr(msaof.lpstrFile, Chr(0)) - 1) End If
SelectExcelDoc = strRet End Function
\' Removes any instances of \'c\' in the end of source-string \'i\' Function TrimAnyChar(i As String, c As String) As String While Right(i, 1) = c i = Mid(i, 1, Len(i) - 1) Wend TrimAnyChar = i End Function
Sub test() MsgBox SelectExcelDoc() MsgBox SimpleGetOpenFileName() End Sub
Horus -> Den virker fint min funktion, den åbner et regneark og henter sti og filnavn, hvorefter excel lukkes. privaten -> Det ser indviklet (sjovt) ud. Jeg vender tilbage.
Privaten -> Det fungere fint, og jeg kan godt se at det er den rigtige måde at gøre det på. Men hvordan ved man at GetOpenFileName funktionen er i comdlg32.dll og hvilke argumenter den tager. Er der et websted man kan søge på ?????
Tak for hjælpen
Synes godt om
Ny brugerNybegynder
Din løsning...
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.