Buongiorno,
Vorrei sapere se è possibile creare una macro che copia un testo di un documento Word e lo incolla in un file aperto con blocco note, per poi salvarla in formato xml.
Grazie anticipatamente!
Moderatori: Anthony47, Flash30005
AppActivate "trzA645.tmp - Blocco note di Windows"
Sub cambia_nome()
Dim I As Long
StartPath = "C:\Users\MiaCartella\"
For I = 1 To 10
' Salvo il file txt
ChangeFileOpenDirectory "C:\Users\MiaCartella\"
ActiveDocument.SaveAs2 FileName:="Mio file_" & I & ".txt", FileFormat:= _
wdFormatText, LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False, Encoding:=1252, InsertLineBreaks:=False, AllowSubstitutions:=False _
, LineEnding:=wdCRLF, CompatibilityMode:=0
'passo alla lettera successiva
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
ChangeFileOpenDirectory "C:\Users\MiaCartella\"
'Cambio nome al file attivo
ActiveDocument.SaveAs2 FileName:="MioFile.txt", FileFormat:= _
wdFormatText, LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False, Encoding:=1252, InsertLineBreaks:=False, AllowSubstitutions:=False _
, LineEnding:=wdCRLF, CompatibilityMode:=0
' cambio nome al primo file
Name StartPath & "Mio file_" & I & ".txt" As StartPath & "Mio file_" & I & ".xml"
Next I
End Sub
miaVar = Workbooks("secondofile.xlsx").Sheets("Foglio1").Cells(I,"C").Value
Dim WXL as Object, WWb as Object 'Dichiarazioni
'..
'..
Set WXL = CreateObject("Excel.Application") 'Crea una sessione nascosta di XL
Set WWb = WXL.Workbooks.Open("C:\Percorso\NomeFile.xlsx") 'Apre il file e
miaVar = WWb.Sheets("Foglio1").Cells(I,"C").Value
WWb.Close False 'Chiudi il file senza salvare
WXL.Quit 'Chiudi la sessione Excel
Set WXL = Nothing 'Piu' per consuetudine che per bisogno...
Set WWb = Nothing 'Idem
Sub crea_xml()
'
' crea_xml Macro
Dim I As Long
Dim WXL As Object, WWb As Object
Set WXL = CreateObject("Excel.Application")
Set WWb = WXL.Workbooks.Open("C:\Users\XXXX.xlsx")
StartPath = "C:\Users\"
For I = 2 To WWb.Sheets("CALENDARIO").Cells(Rows.Count, "P").End(xlUp).Row
' Salvo il file txt
ChangeFileOpenDirectory "C:\Users\"
ActiveDocument.SaveAs2 FileName:="n_T-" & I & "-2021.txt", FileFormat:= _
wdFormatText, LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False, Encoding:=1252, InsertLineBreaks:=False, AllowSubstitutions:=False _
, LineEnding:=wdCRLF, CompatibilityMode:=0
'passo alla lettera successiva
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
ChangeFileOpenDirectory "C:\Users\"
'Cambio nome al file attivo
ActiveDocument.SaveAs2 FileName:="n.txt", FileFormat:= _
wdFormatText, LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False, Encoding:=1252, InsertLineBreaks:=False, AllowSubstitutions:=False _
, LineEnding:=wdCRLF, CompatibilityMode:=0
' cambio nome al primo file
Name StartPath & "n_T-" & I & "-2021.txt" As StartPath & "n_T-" & I & "-2021.xml"
Next I
WWb.Close False
WXL.Quit
Set WXL = Nothing
Set WWb = Nothing
End Sub
For I = 2 To WWb.Sheets("CALENDARIO").Cells(Rows.Count, "P").End(xlUp).Row
Name StartPath & "n_T-" & I & "-2021.txt" As StartPath & "n_T-" & I & "-2021.xml"
Name StartPath & "n_T-" & I & "-2021.txt" As StartPath & "n_T-" & miaVar & "-2021.xml"
Application.Wait (Now + TimeValue("0:00:01"))
WXL.Application.wait (Now + TimeValue("0:00:05"))
#If VBA7 Then '!!! ON TOP OF THE VBA MODULE !!!!
Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
#Else
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If
Sleep 500 'Attesa 500 msec
Torna a Applicazioni Office Windows
Macro per aprire file salvato su sharepoint Onedrive Autore: marcopont |
Forum: Applicazioni Office Windows Risposte: 2 |
Importare immagini a seconda del testo in una cella Autore: Paolo67met |
Forum: Applicazioni Office Windows Risposte: 4 |
Come impostare il formato data predefinito in excel? Autore: wallace&gromit |
Forum: Applicazioni Office Windows Risposte: 5 |
Come interrompere macro sndPlaySound Autore: systemcrack |
Forum: Applicazioni Office Windows Risposte: 2 |
Inserire valore di una cella in altra cella con testo Autore: Ricky0185 |
Forum: Applicazioni Office Windows Risposte: 17 |
Visitano il forum: Nessuno e 27 ospiti