2013-03-20 4 views
3

나는 약간의 온 전성 체크가 필요하다고 생각합니다. 저는 Mac 용 Word Add-in (Word 2010 용 VBA로 작성)을 구체적으로이 시점에서 Word 2011에 적용하고 있습니다. 많은 차이점을 알고 있지만 아직 찾지 못한 점이 있습니다. 많은 문서가 FileDialog의 명백한 부족이다. 가장 가까운 대답은 다음과 같습니다. http://www.rondebruin.nl/mac.htm 여기서 작성자는 Application.GetOpenFilename을 사용합니다. 그 방법은 Word에서는 존재하지 않는 것 같습니다 (해당 사이트의 초점은 Excel입니다).Word 2011의 FileDialog VBA

누구든지 FileDialog에서 사용할 수있는 파일 및 폴더 선택 대화 상자를 사용하는 방법을 알고 있습니까? Applescript에 익숙하지 않지만 Word 2011의 펑키 한 파일 관리 문제 (Dir, FileCopy 등)를 해결하기 위해 조금 배워야했습니다. 그 대답이라면 Applescript에서 코드가 어떻게 보일지에 대한 어떤 감각도 크게 감사 할 것입니다. (나는 VBA로 그것을 번역하는 방법을 어느 정도 알고있다).

+1

Mac 용 VBA에 대해서는 잘 모르지만 다음 [post] (http://stackoverflow.com/questions/15518682/to-add)에서 살펴볼 수 있습니다. -header-and-footer-for-many-word-documents/15520412 # 15520412) Word 2010의 'msoFileDialogFilePicker'에 대한 정확한 구조를 제시합니다. –

+0

고마워요, 그게 내 추가 기능을 현재 작성한 것입니다. FileDialog는 Word 2011에서 "사용자 정의 유형"오류를 발생시킵니다. 따라서 다른 것으로 불리거나이 대화 상자는 콘텐츠 모델을 통해 액세스 할 수 없습니다. – Christina

답변

4

Mac에서이 작업을 더 잘 수행하려면 Apple Script를 사용해야한다고 생각합니다. 다음 코드를 사용하면 함수에서 배열로 반환 된 텍스트 파일을 선택할 수 있습니다. 다른 파일 형식을 반환하고 디렉토리를 선택하도록 Apple Script를 수정할 수 있습니다.이 파일을 남겨 두겠습니다.

함수를 호출하고 메시지의 모든 파일과 상자를 표시하는 코드 :

Sub GetTextFilesOnMac() 
    Dim vFileName As Variant 

    'Call the function to return the files 
    vFileName = Select_File_Or_Files_Mac 

    'If it's empty then the user cancelled 
    If IsEmpty(vFileName) Then Exit Sub 

    'Loop through all the files specified 
    For ii = LBound(vFileName) To UBound(vFileName) 
     MsgBox vFileName(ii) 
    Next ii 

End Sub 

그리고 애플 스크립트 작업 수행 기능 : 마지막으로

Function Select_File_Or_Files_Mac() As Variant 
    'Uses AppleScript to select files on a Mac 
    Dim MyPath As String, MyScript As String, MyFiles As String, MySplit As Variant 

    'Get the documents folder as a default 
    On Error Resume Next 
    MyPath = MacScript("return (path to documents folder) as String") 

    'Set up the Apple Script to look for text files 
    MyScript = "set applescript's text item delimiters to "","" " & vbNewLine & _ 
      "set theFiles to (choose file of type " & " {""public.TEXT""} " & _ 
      "with prompt ""Please select a file or files"" default location alias """ & _ 
      MyPath & """ multiple selections allowed true) as string" & vbNewLine & _ 
      "set applescript's text item delimiters to """" " & vbNewLine & _ 
      "return theFiles" 

    'Run the Apple Script 
    MyFiles = MacScript(MyScript) 
    On Error GoTo 0 

    'If there are multiple files, split it into an array and return the results 
    If MyFiles <> "" Then 
     MySplit = Split(MyFiles, ",") 
     Select_File_Or_Files_Mac = MySplit 
    End If 
End Function 

, 그것은 될 수있는 Word 문서 만 지정하려면 public.TEXTcom.microsoft.word.doc으로 바꾸십시오. 그러나 .docx 또는 .docm 개의 파일은 허용되지 않습니다. 이 경우 각각 org.openxmlformats.wordprocessingml.documentorg.openxmlformats.wordprocessingml.document.macroenabled을 사용해야합니다. 자세한 내용은 https://developer.apple.com/library/mac/#documentation/FileManagement/Conceptual/understanding_utis/understand_utis_conc/understand_utis_conc.html

+0

정말 대단합니다. 고마워요! 내가 필요한 것. – Christina

+0

도와 드리겠습니다. Mac에서 VBA의 추가 즐거움! :) – CuberChase