2012-03-06 4 views
0

먼저 꺼내기가 쉽습니다. 초보자입니다. 여러 개의 통합 문서로 만들고 저장하는 서식 파일 통합 문서에서 여러 유형의 셀 (예 : 문자열, 복식)을 참조해야합니다. 내 마스터 파일로 전송할 값이나 문자열을 얻는 방법을 알아 냈지만 통합 문서 중 하나를 열고 값을 변경하여 마스터 파일을 변경할 수 있기를 원합니다. 또한 마스터 통합 문서는 다른 통합 문서와 다른 위치에 저장됩니다. 어떤 도움을 주시면 감사하겠습니다.다른 유형의 셀 참조 (예 : 문자열, 복식) - 여러 통합 문서

감사

Sub HyperLink() 

    'This macro creates a new excel workbook based on the selected part number of the master file. 
    'It also fills in three cells in the newly created excel file based on the master. 
    'Certain cells in the newly created workbook are referenced back to the master 
    'Finally the part number in the master excel is hyperlinked to the newly created excel 

    Dim PartNumber As String 
    Dim EAU As Integer 
    Dim CurrentMaterial As Double 
    Dim SimForging As String 
    Dim EstForging As String 
    Dim ProcessSavings As String 

    ColumnLocation = ActiveCell.Column 
    CellLocation = ActiveCell.Address 

    PartNumber = Cells(ActiveCell.Row, ActiveCell.Column) 'Defines the part number for the active cell 
    EAU = ActiveCell.Offset(0, 1).Value 'Defines the EAU for the selected part number (column C) 
    CurrentMaterial = ActiveCell.Offset(0, 2).Value 'Defines the Mat. Cost for the selected part number (column D) 

    With Application 
     CalcMode = .Calculation 
     .Calculation = xlCalculationManual 
     .ScreenUpdating = False 
     .EnableEvents = False 
    End With 

    If IsNull(PartNumber) = False Then 
     Workbooks.Add 
     FilePath = "C:\Documents and Settings\Brandon's\Desktop\Forging Justification\" & PartNumber & ".xlsx" 
     Workbooks.Open Filename:="C:\Documents and Settings\Brandon's\Desktop\Forging Justification\Template.xls" 
     Range("A2").Select 
     ActiveWorkbook.SaveAs Filename:=FilePath, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False 
     Range("A2").Select 
     ActiveCell.Value = PartNumber 
     ActiveCell.Offset(4, 0).Value = EAU 
     ActiveCell.Offset(0, 3).Value = CCur(CurrentMaterial) 

     'I dont know what to use here????????????????????? 
     SimForging = Range("A8").FormulaR1C1 
     ProcessSavings = Range("C11").FormulaR1C1 
     EstForging = Range("F2").FormulaR1C1 

     ActiveWorkbook.Save 
     ActiveWindow.Close 
     ActiveWindow.Close 

     ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="Pricing\" & PartNumber & ".xlsx", TextToDisplay:=PartNumber 

     'Again I don't know what to do here in order to make it dynamic???????????? 
     'I want to be able to change the EstForging in PartNumber.xlsx and have it update the master file 
     ActiveCell.Offset(0, 4) = EstForging 
     ActiveCell.Offset(0, 5) = SimForging 
     ActiveCell.Offset(0, 7) = ProcessSavings 

     ActiveWorkbook.Save 

     With Application 
      .ScreenUpdating = True 
      .EnableEvents = True 
      .Calculation = CalcMode 
     End With 
    End If 

End Sub 

Siddarth, 응답에 대한

덕분에, 그것은 다음과 같이 작동합니다.

셀 (A PARTNUMBER 예. 1234) 나에 대한 매크로를 실행하고 시작하려는를 선택 매크로

1) PARTNUMBER, EAU와 CurrentMaterial
PARTNUMBER = 세포 (ActiveCell.Row, ActiveCell.Column 정의) EAU을 ActiveCell.Offset = (0, 1) .Value
CurrentMaterial을 ActiveCell.Offset = (0, 2)

2 .Value

) I 만든 템플릿을 연다. Workbooks.Open 파일 이름 : = "X : 새로운 부품 \ - 밀러, Crum 보낸 \ 정당성의 \의 Template.xls 단조".

3) (새로운 파일로 Template.xls를 저장 즉 1234.xlsx를)
를 " C : \ 문서 및 설정 \ 브랜든의 \ Desktop은 \ 단조 정당성 \ "& PARTNUMBER &는"A2 ")"를 1234.xlsx
범위 (에 PARTNUMBER, EAU와 CurrentMaterial 장소)

4 ".xlsx '에 선택합니다.
ActiveCell.Value = PartNumber
ActiveCell.Offset (3, 0). 값 = EAU,210 을 ActiveCell.Offset (0, 3) .Value = CCur (CurrentMaterial)

5)에 SimForging, EstForging 및 ProcessSavings을 정의 1234.xlsx
SimForging을 ActiveCell.Offset =() =
EstForging를 ActiveCell. 오프셋 (,)
ProcessSavings = ActiveCell.Offset (,)

6) 1234.xlsx를 저장하고 닫습니다. 다시 활성화 마스터 파일

7), (,)가 PARTNUMBER
을 ActiveCell.Offset 동일한 행 Simforging, EstForging 및 ProcessSavings 배치 = SimForging
을 ActiveCell.Offset() =
를 ActiveCell을 EstForging. = 선택, 주소 : 오프셋 (,)는 ProcessSavings

8

가) 난 그냥 (1234.xlsx)
ActiveSheet.Hyperlinks.Add 앵커를 만든 파일에 PARTNUMBER 셀에 하이퍼 링크를 추가 = = "가격 \"&을 PartNumber & ".xlsx", _ TextToDisplay : = PartNumber

9) 마스터 통합 문서를 저장하고 매크로를 중지하십시오.

그런 다음 하이퍼 링크를 누르고 1234.xlsx를 열 수 있기를 원합니다.
그런 다음 1234.xlsx 내부의 ProcessSavings을 변경하고 저장하고 닫습니다.
마스터 통합 문서의 변경 내용을보고 싶습니다.

지금까지 1234.xlsx에서 값을 가져올 수 있었지만 변경 한 경우 마스터 파일에서 업데이트되지 않습니다 ???? EstForging 및 ProcessSavings은 복식이며 SimForging은 문자열입니다.

+0

포인트 5를 명확히 해주시겠습니까? 어디에서 값을 가져 오려고합니까? –

+0

새로 만든 엑셀 (예 : 1234.xlsx)의 셀을 마스터 통합 문서로 다시 참조하려고합니다. 그래서 마스터 통합 문서 내에서이 ActiveCell.Offset (0,23) = "= 'C : \ Documents and Settings \ Brandon의 \ Desktop \ Forge Justification \ [1234.xlsx] Sheet1'과 같은 것을 할 것입니다! $ C $ 11" – user1251120

+0

그런 식을 SimForging에 저장하려고합니까? –

답변

0
'I dont know what to use here????????????????????? 
    SimForging = Range("A8").FormulaR1C1 
    ProcessSavings = Range("C11").FormulaR1C1 
    EstForging = Range("F2").FormulaR1C1 

이 당신이하려고하는 무엇인가?

귀하의 요구 사항과 혼동 스럽습니다. 매크로가 어떻게 행동해야 하는지를 가리킬 수 있습니까? 내 말은 매크로가 취해야 할 단계를 지정하는 것입니다. 설명에 파일 이름과 셀 주소를 사용하십시오. 예를

1) 매크로

2)를 사용하여 현재 통합 문서

3) 파일 이름 결정에 활성 셀에서 PARTNUMBER, EAU, CurrentMaterial을 가져

"C:\Documents and Settings\Brandon's\Desktop\Forging Justification\" & PartNumber & ".xlsx"

시작이 참조

4) 마스터 파일 열기 "C:\Documents and Settings\Brandon's\Desktop\Forging Justification\Template.xls"

기타 등등 ...

우리가 정확히 원하는 것을 이해하면 우리는 훨씬 더 나은 방법으로 당신을 도울 수 있습니다. :)

시드

+0

예, ProcessSavings = Range ("C11")을 시도했지만 값은 업데이트되지 않았습니다. – user1251120

+0

@ user1251120 : 질문에 올린 의견을 참조하십시오. –