preciso fazer uma macro no excel que abra uma caixa de dialogo, eu escolha o arquivo do excel desejado e, ao abrir, importasse para o proprio arquivo q estou trabalhando.
pra especificar melhor..eu tenho um codigo q faz quase isso..mas não sei onde eu posso modificar.
alguém pode ajudar
Dim DestBook As Workbook, SourceBook As Workbook
Dim DestCell As Range
Dim RetVal As Boolean
' Turn off screen updating.
Application.ScreenUpdating = False
' Set object variables for the active book and active cell.
Set DestBook = ActiveWorkbook
Range("A1").Activate
Set DestCell = ActiveCell
' Show the Open dialog box.
RetVal = Application.Dialogs(xlDialogOpen).Show("*.xls")
' If Retval is false (Open dialog canceled), exit the procedure.
If RetVal = False Then Exit Sub
' Set an object variable for the workbook containing the text file.
Set SourceBook = ActiveWorkbook
' Copy the contents of the entire sheet containing the text file.
Range(Range("A1"), Range("A1").SpecialCells(xlLastCell)).Copy
' Activate the destination workbook and paste special the values
' from the text file.
DestBook.Activate
DestCell.PasteSpecial Paste:=xlValues
' Close the book containing the text file.
SourceBook.Close False
Pergunta
thur
preciso fazer uma macro no excel que abra uma caixa de dialogo, eu escolha o arquivo do excel desejado e, ao abrir, importasse para o proprio arquivo q estou trabalhando.
pra especificar melhor..eu tenho um codigo q faz quase isso..mas não sei onde eu posso modificar.
alguém pode ajudar
Dim DestBook As Workbook, SourceBook As Workbook Dim DestCell As Range Dim RetVal As Boolean ' Turn off screen updating. Application.ScreenUpdating = False ' Set object variables for the active book and active cell. Set DestBook = ActiveWorkbook Range("A1").Activate Set DestCell = ActiveCell ' Show the Open dialog box. RetVal = Application.Dialogs(xlDialogOpen).Show("*.xls") ' If Retval is false (Open dialog canceled), exit the procedure. If RetVal = False Then Exit Sub ' Set an object variable for the workbook containing the text file. Set SourceBook = ActiveWorkbook ' Copy the contents of the entire sheet containing the text file. Range(Range("A1"), Range("A1").SpecialCells(xlLastCell)).Copy ' Activate the destination workbook and paste special the values ' from the text file. DestBook.Activate DestCell.PasteSpecial Paste:=xlValues ' Close the book containing the text file. SourceBook.Close FalseEditado por kuroiAdicionar tag CODE
Link para o comentário
Compartilhar em outros sites
1 resposta a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.