Consulting

Results 1 to 3 of 3

Thread: Save As a part of text in document

  1. #1
    VBAX Newbie
    Joined
    Nov 2011
    Posts
    1
    Location

    Save As a part of text in document

    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 ...
    [VBA]
    Set fldlg = Application.FileDialog(msoFileDialogSaveAs)
    fldlg.InitialFileName = strClientsPath & "P:\Projekti\FMS_INA\Projekt Siemens-EKUS\Ponude_Poslane\"
    fldlg.Show
    fldlg.Execute
    [/VBA]

    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 ...

    [VBA]

    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[/VBA]

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

    Thanks in advance

  2. #2
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    [vba]
    Set fldlg = Application.FileDialog(msoFileDialogSaveAs)
    fldlg.InitialFileName = strClientsPath & _
    "P:\Projekti\FMS_INA\Projekt Siemens-EKUS\Ponude_Poslane\" & Selection.Range.Text
    fldlg.Show
    fldlg.Execute
    [/vba]

    David


  3. #3
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •