2013-10-15 3 views
0

Sub()에서 사용할 때 내 함수의 return을 catch 할 수 없습니다. 내 기능은 다음과 같습니다. 그것은 내 Sub()와 같은 모듈에있다.함수에서 반환 된 데이터를 가져올 수 없습니다.

Option Explicit 
Public Function GetMyPath(ByVal strPath As String) As String 
' Get the directory strPath from the user 
' strPath is the default path given by the function argument 

Dim fldr As FileDialog 
Set fldr = Application.FileDialog(msoFileDialogFolderPicker) 

On Error GoTo 0 

With fldr 
    .Title = "Selectionner un dossier" 
    .AllowMultiSelect = False 
    .InitialFileName = strPath 
     If .Show <> -1 Then GoTo NextCode 
     strPath = .SelectedItems(1) 
End With 

NextCode: 
Set fldr = Nothing 

End Function 

보시다시피, 사용자가 선택한 경로를 문자열로 반환합니다. 이 함수는 최종 MsgBox()가 선택한 경로를 올바르게 표시하므로 제대로 작동합니다. 지금 내 서브()의 첫 번째 부분은 내가 잘못

Sub SaveToPDF() 
'Export RngToExport as FileFormat to MyPath 

Dim ToDate As String 
Dim ws As Worksheet 
Dim RngSelect As Range 
Dim Response As Integer 
Dim Fileformat As Excel.XlFileFormat 
Dim RngToExport, NameOfWorker As Variant 
Dim MyPath As String 



Set ws = Workbooks("Gestion_salaires.xlsm").Application.Sheets("Export") 
Set RngToExport = ws.Range(Cells(1, 1), Cells(43, 7)) 
Set NameOfWorker = Cells(14, 19) 

MyPath = "Y:\BATORA_BATURIX\Employes\Walter H. BAQUE B\bulletin_salaire\" 

''We want to warn about errors before saving 
If Cells(12, 21).Value <> 0 Or Cells(12, 22) <> 0 Or Cells(12, 23) > 0 Then GoTo Warning_ 


Response = MsgBox(Prompt:="Voulez-vous utiliser l'emplacement par défaut ?", Buttons:=vbYesNo) 
    If Response = vbNo Then 
    MyPath = GetMyPath("C:\") 
    End If 

MsgBox(MyPath) '' just for debuging. MyPath is empty :-(

을 뭐하는 거지? 쓰기가 Set MyPath = GetMyPath("C:\")은 개체가 아니기 때문에 작동하지 않습니다. 도움 주셔서 감사합니다. 최종 기능 전에

GetMyPath = strPath 

:

답변

2

당신은 같은 라인을 삽입해야합니다.

그렇지 않으면 문자열이 함수 밖으로 전달되지 않습니다.

+0

아주 좋습니다. 타이 대답 해줘. 문제가 해결되면 [SOLVED] 태그로 내 질문 제목을 편집하는 것이 가장 좋습니다. – gabx

+1

누군가가 내 질문에 대답 할 때 수행 할 작업을 보려면 [여기] (http://stackoverflow.com/help/someone-answers)를 참조하십시오. – barrowc

관련 문제