+ Reply to Thread
Results 1 to 2 of 2

SaveAs to a File with name from Clipboard

Hybrid View

  1. #1
    Registered User
    Join Date
    07-25-2017
    Location
    Denver, Colorado
    MS-Off Ver
    Excel for PC 2016
    Posts
    1

    Question SaveAs to a File with name from Clipboard

    Hello all,

    I am stuck in a macro that I am making that automatically formats an excel document. I will have several questions throughout the process I am sure, but I will start with the SaveAs process.

    I would also like to note that I am not new to programming, but I am very new to VBA and there is likely simple answers to my questions, so thank you for your patience.

    So, I am trying to save my file as a specific name that is a portion of a value from a specific cell in the second sheet of the workbook. Here is the code.

    '

    Sheets("Sheet2").Select
    Range("F6").Select
    Dim objData As New DataObject
    Dim strTemp As String
    strTemp = ActiveCell.Value
    objData.SetText (strTemp)
    objData.PutInClipboard

    Dim DataObj As New MSForms.DataObject
    Dim fileName As String
    DataObj.GetFromClipboard
    fileName = DataObj.GetText

    ActiveWorkbook.SaveAs fileName:="C:\Users\a87078\Desktop\Splunk Documents\Splunk" & fileName & ".xlsm", FileFormat:=52, CreateBackup:=False

    '

    Clipboard functions confuse me, as solutions never seem to be consistent on forums. I am getting an error on the "fileName" portion of the last line. I need to remove a portion of the data from the cell aswell, such as "This is the CellValue" and I need it to SaveAs only "CellValue", which I am accomplishing using a SUBSTITUTE() function given that the "This is the " portion is always a constant and doesn't change from workbook to workbook.

    All of this together is proving to be a lot of trouble. Any help would be greatly appreciated. The next step in the macro will be regarding selecting specific ranges of cells based on their contents (as well as an offset cell one to the right of said cell.)

    Thanks!

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: SaveAs to a File with name from Clipboard

    Why not just:

    Filename=Sheets("Sheet2").Range("F6").Value
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Problem With Open File and Save File With Saveas and then close the File
    By John Vieren in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-27-2013, 12:53 AM
  2. Macro to create a new file, saveas and close file
    By kaismum in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-21-2006, 09:34 AM
  3. saveas CSV file
    By stevekirk in forum Excel General
    Replies: 0
    Last Post: 08-10-2006, 08:11 AM
  4. How can I make File->Save , File->SaveAs Menu disabled?
    By Zoo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-05-2006, 02:00 AM
  5. [SOLVED] Saveas csv file
    By Fib in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-09-2006, 10:25 AM
  6. [SOLVED] SaveAs file lost
    By Aaron in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-23-2006, 03:20 PM
  7. [SOLVED] File SaveAs
    By FinChase in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-06-2006, 09:45 PM
  8. SaveAs and File Exists
    By Office User in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-15-2005, 02:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1