saving selection as new workbook

pooadrid

New Member
Joined
Nov 24, 2014
Messages
14
So currently I have a code that when I hit the button, it will automatically bring up the save as screen (to csv) where I can type in the filename and hit save and its done.

what I want to happen on a separate button is the same thing, however, I want it to save the selection with only the values keeping the format(background colors etcs) as another excel workbook, AND grab the filename from a specific cell.


Sub CSVFile()


Dim SrcRg As Range


Dim CurrRow As Range


Dim CurrCell As Range


Dim CurrTextStr As String


Dim ListSep As String


Dim FName As Variant


FName = Application.GetSaveAsFilename("", "CSV File (*.csv), *.csv")


ListSep = Application.International(xlListSeparator)


If Selection.Cells.Count > 1 Then


Set SrcRg = Selection


Else


Set SrcRg = ActiveSheet.UsedRange


End If


Open FName For Output As #1





For Each CurrRow In SrcRg.Rows


CurrTextStr = ìî


For Each CurrCell In CurrRow.Cells


If IsNumeric(CurrCell.Value) Then


CurrTextStr = CurrTextStr & CurrCell.Value & ListSep


Else


CurrTextStr = CurrTextStr & "" & CurrCell.Value & "" & ListSep


End If


Next


While Right(CurrTextStr, 1) = ListSep


CurrTextStr = Left(CurrTextStr, Len(CurrTextStr) - 1)


Wend





Print #1, CurrTextStr


Next


Close #1


End Sub

ive have tried different codes and macros and for the life of me cant get it to work. but this code here does what I want for CSV....but I basically just need to modify this code to do what I need for the Xlsx file...which I cant get it to do...please help :(
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top