ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

°»´ú"1.xls"ÀɬO§_§e¥´¶}ª¬ºA?

°»´ú"1.xls"ÀɬO§_§e¥´¶}ª¬ºA?

½Ð±Ð¦U¦ì¤j¤j:
        ­Ó¤H¦b¥ÎVBA¥´¶}¥t¥~ExcelÀɦp"1.xls"ÀÉ,­Y³{"1.xls"ÀÉ¥»¨Ó´N¤w§e¥´¶}ª¬ºA®É,´N¤£¤Ó«ê·í¡C
½Ð±Ð¦U¦ì¥ý¶i­Y­n°»´ú"1.xls"ÀɬO§_§e¥´¶}ª¬ºA?À³¦p¦ó¹B¥ÎVBA»yªk?

«Øij¤@¶}©l´N±N¡A¸ô®|»PÀɦW³]©w¦¨¤£¦PÅܼơC¤è«K¤§«á§Q¥Î¡C
¥t¥~
'¨ú±o¸ô®|»PÀɦW(¤£¥]¬A°ÆÀɦW)
'The following function returns the filename without the extension from the file's full path:
Function FileNameNoExt(strPath As String) As String
    Dim strTemp As String
    strTemp = Mid$(strPath, InStrRev(strPath, "\") + 1)
    FileNameNoExt = Left$(strTemp, InStrRev(strTemp, ".") - 1)
End Function

'¨ú±o§¹¾ãÀɦW
'The following function returns the filename with the extension from the file's full path:
Function FileNameWithExt(strPath As String) As String
    FileNameWithExt = Mid$(strPath, InStrRev(strPath, "\") + 1)
End Function

'¨ú±o¸ô®|
'the following function will get the path only (i.e. the folder) from the file's ful path:
Function FilePath(strPath As String) As String
    FilePath = Left$(strPath, InStrRev(strPath, "\"))
End Function

TOP

«Øij¤@¶}©l´N±N¡A¸ô®|»PÀɦW³]©w¦¨¤£¦PÅܼơC¤è«K¤§«á§Q¥Î¡C
¥t¥~
'The following function returns the filename without the extension from the file's full path:
Function FileNameNoExt(strPath As String) As String
    Dim strTemp As String
    strTemp = Mid$(strPath, InStrRev(strPath, "\") + 1)
    FileNameNoExt = Left$(strTemp, InStrRev(strTemp, ".") - 1)
End Function

'The following function returns the filename with the extension from the file's full path:
Function FileNameWithExt(strPath As String) As String
    FileNameWithExt = Mid$(strPath, InStrRev(strPath, "\") + 1)
End Function

'¨ú±o¸ô®|
'the following function will get the path only (i.e. the folder) from the file's ful path:
Function FilePath(strPath As String) As String
    FilePath = Left$(strPath, InStrRev(strPath, "\"))
End Function

TOP

¦^´_ 15# Hsieh
¨º¦³¤°»ò´ê¼ö¾xªº,½×¾Â¬O¶V¼ö¾x¶V¦n

TOP

¦^´_ 18# Hsieh

ÁÂÁ §¹¥þ¤F¸Ñ

TOP

¦^´_ 16# yangjie


    ³o¬O¤£¤@¼Ëªº
¦]¬°filename³Q«Å§i¬°string©Ò¥Hfilename="FALSE"¤~¬O¥¿½T
­Y¬°filename=FALSE³o¬OÅܦ¨ÅÞ¿è­È§PÂ_
filename¥²¶·¬O¥¬ªL­È
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦^´_ 15# Hsieh
¤ô°Õ
Á¤F

TOP

¦^´_ 14# GBKEE
Á¤F
if Ucase(filename)="FALSE" then
»P
if filename=False then
¥i¦³¬Û²§

TOP

¦^´_ 14# GBKEE

´ê¼ö¾x¡AFullName¥h°£¸ô®|¥u³ÑÀɦW
    xlfileName = Dir(xlFullName)
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦^´_ 13# yangjie
  1. Option Explicit
  2. Sub ¿ï¾ÜÀɦW¶×¤J()
  3.     Dim Path1, Str1 As String
  4.     Dim wb As Workbook
  5.     Dim Filt As String
  6.     Dim FilterIndex As Integer
  7.     Dim Title As String
  8.     '---------------------------------
  9.     Dim xlfileName As String, xlFullName As String
  10.     '­×§ï«¬ºA As String  xlfileName:¨S¦³¸ô®|
  11.     Dim MyPath
  12.     MyPath = CurDir    '¬ö¿ý­ì¦³ªº¥Ø¿ý©ÎÀɮק¨¡C
  13.     Path1 = Application.ActiveWorkbook.Path
  14.    ' Path1 = "C:\WINDOWS\SYSTEM"
  15.     ChDrive Split(Path1, ":")(0)    'ChDrive ³¯­z¦¡ §ïÅܥثeªººÏºÐ¾÷¡C
  16.     ChDir Path1                     'ChDir   ³¯­z¦¡ §ïÅܥثeªº¥Ø¿ý©ÎÀɮק¨¡C
  17.     '½Ðª`·N ChDir ³¯­z¦¡·|§ïÅܲ{¦³¥Ø¿ý¦ì¸m¡A¦ý¤£·|§ïÅܺϺо÷¦ì¸m¡A
  18.     '¨Ò¦p¡A¦pªG²{¦bªººÏºÐ¾÷¬O C¡A³¯­z¦¡±N²{¦³¥Ø¿ý¤Á´«¨ìºÏºÐ¾÷ D¡A¦ý¬O C ¤´µM¬O²{¦³ªººÏºÐ¾÷¦ì¸m¡G
  19.     Filt = "Excel Files (*.xls),*.xls"
  20.     FilterIndex = 5
  21.     Title = "Select a File for Import"
  22.     xlFullName = Application.GetOpenFilename _
  23.         (FileFilter:=Filt, _
  24.          FilterIndex:=FilterIndex, _
  25.          Title:=Title)
  26.    
  27.     If UCase(xlFullName) = "FALSE" Then
  28.         MsgBox "No file was selected."
  29.         Exit Sub
  30.     End If
  31.     '''''''''''''''''''''''''
  32.     ChDrive Split(MyPath, ":")(0)    '§ïÅܬ°­ì¦³ªººÏºÐ¾÷¡C
  33.     ChDir MyPath                     '§ïÅܬ°­ì¦³ªº¥Ø¿ý©ÎÀɮק¨¡C
  34.     ''''''''''''''''''''''''''
  35.    
  36.     xlfileName = Split(xlFullName, "\")(UBound(Split(xlFullName, "\")))
  37.     '°}¦C(¤W­­¤¸¯À¼Æ) ¨úªºÀɮצWºÙ¨S¦³¸ô®|
  38.     If IsOpen(xlfileName) <> False Then
  39.         Workbooks(xlfileName).Activate
  40.     Else
  41.         Set wb = Workbooks.Open(xlFullName, True, False)
  42.     End If
  43.     f_bookname2 = ActiveWorkbook.Name
  44.     Windows(f_bookname2).Activate
  45.     Sheets(1).Activate
  46. End Sub
  47. Function IsOpen(Fs As String) As Boolean
  48.     IsOpen = False
  49.     For Each W In Windows
  50.          If W.Caption = Fs Then IsOpen = True: Exit For
  51.    Next
  52. End Function
½Æ»s¥N½X

TOP

        ÀR«ä¦Û¦b : ¡i®É¶¡¦pÆp¥Û¡j®É¶¡¹ï¤@­Ó¦³´¼¼zªº¤H¦Ó¨¥¡A´N¦pÆp¥Û¯ë¬Ã¶Q¡F¦ý¹ï·M¤H¨Ó»¡¡A«o¹³¬O¤@§âªd¤g¡A¤@ÂI»ù­È¤]¨S¦³¡C
ªð¦^¦Cªí ¤W¤@¥DÃD