- ©«¤l
- 41
- ¥DÃD
- 7
- ºëµØ
- 0
- ¿n¤À
- 52
- ÂI¦W
- 0
- §@·~¨t²Î
- Windows10
- ³nÅ骩¥»
- 2019
- ¾\ŪÅv
- 20
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2017-11-28
- ³Ì«áµn¿ý
- 2024-2-1
|
[¤À¨É] VBA-¤@¦¸§ó·s§AWORD¸Ì±¡A©Ò¦³³s°ÊEXCELÀx¦s®æ³sµ²!
¤p§Ì°µ³ø§i®Ñªº²ßºD´N°¾¦n³s°ÊEXCEL¸Ì±¯S©wÀx¦s®æ¡C
¨Ò¦p
{ LINK Excel.SheetMacroEnabled.12 "D:\\®×¥ó\\¶}µo®×\\¤ô²zpºâ.xlsm" ªì´Á³]©w!R4C4 \t }
ê©ó¸Ì±¦³¦s¦b«Ü¦h³sµ²¨ì§OªºWORD®ÑÅÒ¡A¾ÉP³Ì¦°µªk³£¬O¦b"ÀÉ®×"->"¸ê°T"->"½s¿èÀɮ׳sµ²" ºCºC§ï
©Ò¥H¤Wºô§ä¤F¥H¤UªºCODE- Public Sub changeSource()
- Dim dlgSelectFile As FileDialog 'FileDialog object '
- Dim thisField As Field
- Dim selectedFile As Variant
- 'must be Variant to contain filepath of selected item
- Dim newFile As Variant
- Dim fieldCount As Integer '
- Dim x As Long
- On Error GoTo LinkError
- 'create FileDialog object as File Picker dialog box
- Set dlgSelectFile = Application.FileDialog(FileDialogType:=msoFileDialogFilePicker)
- With dlgSelectFile
- .Filters.Clear 'clear filters
- .Filters.Add "Microsoft Excel Files", "*.xls, *.xlsb, *.xlsm, *.xlsx" 'filter for o nly Excel files
- 'use Show method to display File Picker dialog box and return user's action
- If .Show = -1 Then
- 'step through each string in the FileDialogSelectedItems collection
- For Each selectedFile In .SelectedItems
- newFile = selectedFile 'gets new filepath
- Next selectedFile
- Else 'user clicked cancel
- Exit Sub
- End If
- End With
- Set dlgSelectFile = Nothing
- 'update fields
- With ActiveDocument
- fieldCount = .Fields.Count
- For x = 1 To fieldCount
- With .Fields(x)
- 'Debug.Print x '
- Debug.Print .Type
- If .Type = 56 Then
- 'only update Excel links. Type 56 is an excel link
- .LinkFormat.SourceFullName = newFile '
- .Update
- .LinkFormat.AutoUpdate = False
- DoEvents
- End If
- End With
- Next x
- End With
- MsgBox "¡I§ó·s§¹¦¨¡I"
- Exit Sub
- LinkError:
- Select Case Err.Number
- Case 5391 'could not find associated Range Name
- MsgBox "Could not find the associated Excel Range Name " & _
- "for one or more links in this document. " & _
- "Please be sure that you have selected a valid " & _
- "Quote Submission input file.", vbCritical
- Case Else
- MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical
- End Select
- End Sub
½Æ»s¥N½X For x = 1 To fieldCount
¦b³o¸Ì§Ú¬O·|§ï¦¨ 1 To 25¡A¤£½T©w³o¤°»ò·N«ä....«¢
°_ªì§Ú¤å¥ó¤º¦³100¦h¶¡A¥i¯à¨C10¶´N·|¦³ÓEXCEL³sµ²¡A¾ÉP¦A¨ê·s®É...·|µ¥«Ü¤[...
©Ò¥H§Ú«á¨Óªº§@ªk´N¬O¦b²Ä¤@¶³]©wªí®æ¨Ã¥[¤J®ÑÅÒ¡A¸Ì±³£¬OEXCEL³sµ²¡A°²³]¸Ì±¦³25Ó¬O³sµ²excelªº....
¦n¹³´N¯uªº·|Ū¨ú³o25Ó....´N·|¶]¤ñ¸û§Ö
¥t¥~§Ú¦³¦Ó¥~³]©w¡A¨C¦¸¶}±ÒWORD ´N·|°õ¦æ³o¥N½X- Sub Document_Open()
- changeSource
- End Sub
½Æ»s¥N½X ¥t¥~¦A¤À¨É¤@Ó¦n¡A¦pªG§A·Qn°Ñ¦Ò§OªºWORDÀɮתº¤º®e¡A¨Ò¦pAÀɮ׳sµ²BÀɮסA¥i¥H¥ý¦bBÀɮ׸̱¡A§A·Qnªº¤å¦r³]©w®ÑÅÒ
¨Ò¦p ³Â»¶®a±Ú°Q½×ª©
¦¹®É§A¥i¥H¦bAÀɮסG
¼ÐÃD¡G³Â»¶®a±Ú°Q½×ª©
{ INCLUDETEXT " {FILENAME \p}\\..\\"BÀÉ®×" "³Â»¶®a±Ú°Q½×ª©" \* MERGEFORMAT }
{}ÃC¦â¯»¦â³oÓ¡A¤@©wn¥Îctrl+p®@!!!
³o¼Ë¤£ºÞ§A©ñ¦bþ¸Ì¡A³£¤£·|¥X²{¿ù»~ÂP¡A¥u¬O³o¨âÓÀɮפ@©wn©ñ¦b®Ç®@ |
|