PDA

View Full Version : Save As a part of text in document



deva_zg
11-08-2011, 04:02 AM
Hello!

I'm new to this forums and to VBA also.
I have a macro that copies some parts of the text to a Excell Workbook.
At the end it prompts me for a filedialog Save as to save it to a specific location.

Like this ...

Set fldlg = Application.FileDialog(msoFileDialogSaveAs)
fldlg.InitialFileName = strClientsPath & "P:\Projekti\FMS_INA\Projekt Siemens-EKUS\Ponude_Poslane\"
fldlg.Show
fldlg.Execute


Is there a way to name the file I'm saving as a text I copied from word to excel?

To be more specific, I'm using the code below ...



wd.Activate
Selection.HomeKey Unit:=wdLine
Selection.HomeKey Unit:=wdLine
Selection.HomeKey Unit:=wdStory
Selection.MoveDown Unit:=wdLine, Count:=10
Selection.MoveRight Unit:=wdWord, Count:=3
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Copy


Set exlapp = CreateObject("Excel.application.11")


Set exlwb = exlapp.Workbooks.Open("P:\Projekti\FMS_INA\Projekt EKUS\Ponude_Poslane\lista_ponuda.xls")
zred = exlwb.Worksheets(1).Cells(Rows.Count, 2).End(xlUp).Row
exlapp.Visible = True

With exlwb.Worksheets(1)

.Cells(zred + 1, 2).Select
.PasteSpecial Format:="Unicode Text", Link:=False, _
DisplayAsIcon:=False

End With

I'd like to name the file as the text that was copied to the excel ...

Thanks in advance

Tinbendr
11-18-2011, 08:57 AM
Set fldlg = Application.FileDialog(msoFileDialogSaveAs)
fldlg.InitialFileName = strClientsPath & _
"P:\Projekti\FMS_INA\Projekt Siemens-EKUS\Ponude_Poslane\" & Selection.Range.Text
fldlg.Show
fldlg.Execute

Jay Freedman
11-18-2011, 06:52 PM
Deva,
Just an additional thing I noticed: You don't need the fldgl.Execute after the fldlg.Show. The Show method both shows the dialog and does the save. The Execute method would then save a second time, which isn't necessary. This is true for all VBA dialogs.