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

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

¦^´_ 4# Hsieh

­ì¨Ó¥Î.Caption´N¥i¥H¨M¸Ñ¡A¤Ó·PÁ§A¤F
{...} ªí¥Ü»Ý­n¥Î CTRL+SHIFT+ENTER ¤TÁä¿é¤J¤½¦¡

TOP

¦^´_ 9# yangjie

Function IsOpen() §Ú´ú¸Õ¬O¥i¥H°õ¦æ

¦ýÀɮצWºÙ¦³¤À¤j¤p¼g¡A¨Ò¦p Book1»PBOOK1´N·|§PÂ_¬°¤£¦P
WINDOW¨t²ÎªºÀÉ®×À³¸Ó¬O¨S¦³¤À¤j¤p¼g(ÁöµMÅã¬O¦³¤j¤p¼g)
{...} ªí¥Ü»Ý­n¥Î CTRL+SHIFT+ENTER ¤TÁä¿é¤J¤½¦¡

TOP

¦^´_ 4# Hsieh
ÁÂÁÂHsiehª©¥D¨ó§Ufunction Isopen()ªº«ü¾É
¦Û­Ó¨àµy·L¦³ÂI¬ð¯}
Sub ¿ï¾ÜÀɦW¶×¤J()
    Dim Path1, Str1 As String
    Dim wb As Workbook
    Path1 = Application.ActiveWorkbook.Path

   
    Dim Filt As String
    Dim FilterIndex As Integer
    Dim fileName As Variant
    Dim Title As String
    Filt = "Excel Files (*.xls),*.xls"
    FilterIndex = 5
    Title = "Select a File for Import"
    fileName = Application.GetOpenFilename _
        (FileFilter:=Filt, _
         FilterIndex:=FilterIndex, _
         Title:=Title)
    If fileName = False Then
        MsgBox "No file was selected."
        Exit Sub
    End If
    Dim fso3
    Set fso3 = CreateObject("Scripting.FileSystemObject")
    GetAn3 = fso3.GetbaseName(fileName)
    If IsOpen(GetAn3 & ".xls") <> False Then
        Workbooks(GetAn3 & ".xls").Activate
    Else
        Set wb = Workbooks.Open(fileName, True, False)
    End If
    f_bookname2 = ActiveWorkbook.Name
    Windows(f_bookname2).Activate
    Sheets(1).Activate
end sub

Function IsOpen(Fs As String) As Boolean
    IsOpen = False
    For Each w In Windows
         If w.Caption = Fs Then IsOpen = True: Exit For
   Next
End Function
¦A½Ð±Ð¤j¤j
   1. ¦p¦óÅýApplication.GetOpenFilename ©Ò¶}¤§µøµ¡¬°path1?
   2.¥i¦³§ó¦nªº¼gªk?
ÁÂÁÂ

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

¦^´_ 14# GBKEE

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

TOP

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

TOP

¦^´_ 15# 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

¦^´_ 18# Hsieh

ÁÂÁ §¹¥þ¤F¸Ñ

TOP

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

TOP

        ÀR«ä¦Û¦b : ¦³®É·í«äµL®É­W¡A¦n¤Ñ­n¿n«B¨Ó³¡C
ªð¦^¦Cªí ¤W¤@¥DÃD