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

[µo°Ý] ChDrive/ ChDir°ÝÃD

[µo°Ý] ChDrive/ ChDir°ÝÃD

ChDrive¥i¥HÅܧó¥Ø«eªººÏºÐ¾÷, ChDir«h¬O¥Î¨Ó§ïÅܥثeªº¸ê®Æ§¨
§Ú¥Î¤U¦C¤è¦¡¼¶¼g:
filepath = ActiveWorkbook.Path
ChDrive filepath
ChDir filepath
filt = "excel files (*.xls;*.xlsx),*.xls;*.xlsx"
Filename = Application.GetOpenFilename(FileFilter:=filt, FilterIndex:=5, title:="¿ï¾ÜÀÉ®×", MultiSelect:=True)
...
...
§Ú¶}±ÒªºexcelÀɮ׬O¦b¬Y¤@­Ó¸ê®Æ§¨(ActiveWorkbook.Path),¥B§Æ±æ°õ¦æopne file®É¶}±Òªº¸ô®|·|¦b¦P¤@­Ó¸ê®Æ§¨,­Y¬O¶}±ÒªºÀɮ׬Oºô¸ôªÚ¾F¤Wªº¹q¸£(§YActiveWorkbook.Path¤£¬O¦b¦Û¤vªº¹q¸£),´N·|¥X²{¿ù»~,½Ð°Ý¸Ó¦p¦ó§ï¤~¯à­×¥¿³o­Ó¿ù»~?

¦^´_ 1# acdx
¸Õ¸Õ¬Ý
  1. Option Explicit
  2. Sub Ex()
  3.     Dim filepath As String, A As String, B As String
  4.     filepath = ActiveWorkbook.Path
  5.    MsgBox CurDir  '***CurDir ¨ç¼Æ¶Ç¦^¤@­Ó Variant (String)¡A¥Î¨Ó¥Nªí¥Ø«eªº¸ô®|¡C
  6.     A = Split(CurDir, "\")(0)
  7.     B = Split(filepath, "\")(0)
  8.     If A <> B Then ChDrive B
  9.     ChDir filepath
  10.     MsgBox CurDir
  11. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¦^´_ 1# acdx
ChDrive : §ïÅܤu§@ºÏºÐ¾÷
ChDir : §ïÅܤu§@¥Ø¿ý
¨ÌÃD¥Øªº·N«ä¬O§Æ±æ GetOpenFilename ¿ï¾ÜÀɮ׮ɪº¹w³]¸ô®|¬°¸ÓÀɸô®|¡A
¦ý·íÀɮצb¤À¨É¸ê®Æ§¨(¸ô¸g³q±`¬° "\\¹q¸£¦WºÙ\¸ê®Æ§¨¸ô®|\ÀÉ®×")
µLªk¥ÎChDir¤Á´«¤u§@¥Ø¿ý¨ì "\\¹q¸£¦WºÙ\¸ê®Æ§¨¸ô®|\"

´À¥N¤èªk¡A³oÃäÁ|¨âºØ :
1. §ï¥Î Application.FileDialog(msoFileDialogOpen)¡AFileDialog¥i¥Hª½±µ³]©wInitialFileName
  1. Sub m1()
  2.     Dim filename As String
  3.     With Application.FileDialog(msoFileDialogOpen)
  4.         .AllowMultiSelect = False
  5.         .InitialFileName = ActiveWorkbook.Path
  6.         .Filters.Clear
  7.         .Filters.Add "Excel files", "*.xlsx;*.xls"
  8.         .Show

  9.         If .SelectedItems.Count = 0 Then Exit Sub   'cancel
  10.         filename = .SelectedItems(1)
  11.     End With
  12.    
  13.     MsgBox filename
  14. End Sub
½Æ»s¥N½X
2. ¥Î windows API : SetCurrentDirectory¤Á´«¤u§@¥Ø¿ý¡A¦A¥Î GetOpenFilename
  1. Private Declare Function SetCurrentDirectory Lib "kernel32" _
  2. Alias "SetCurrentDirectoryA" (ByVal lpPathName As String) As Long

  3. Sub m2()
  4.     Dim filt As String, filename As String
  5.     SetCurrentDirectory ActiveWorkbook.Path
  6.     filt = "excel files (*.xls;*.xlsx),*.xls;*.xlsx"
  7.     filename = Application.GetOpenFilename(FileFilter:=filt, FilterIndex:=5, Title:="¿ï¾ÜÀÉ®×", MultiSelect:=True)
  8. End Sub
½Æ»s¥N½X
ªí¹F¤£²M¡BÃD·N¤£©ú½T¡B¨SªþÀɮ׮榡¡B¨S¦³°Q½×°ÝÃDªººA«×~~~~~~¥H¤W·R²ö¯à§U¡C

TOP

        ÀR«ä¦Û¦b : ¤Ó¶§¥ú¤j¡B¤÷¥À®¦¤j¡B§g¤l¶q¤j¡A¤p¤H®ð¤j¡C
ªð¦^¦Cªí ¤W¤@¥DÃD