Help with VBA code to automate copying selection to new File

Dwaashaas

New Member
Joined
Apr 24, 2014
Messages
2
Hi there,

Im trying to write some code that selects a range of cells, different every time, that exports it to a new file with a predifined file name except voor the weeknumber.

I first make a selection of the cells I want by filtering on weeknumber.
After that I use to following code to export it to a new file;

/code

Sub Exportplanning()

Dim strFileName As String

strFileName = "Uitvoeringsplanning BRTTI 2014 week " & InputBox("Geef de desbetreffende weken aan en geef aan of het om voorlopig gaat (v) of definitief (def) Uitvoeringsplanning BRTTI 2014 week ..", "Geef de bestandsnaam op")
If Trim(strFileName) = vbNullString Then Exit Sub

Application.ScreenUpdating = False
Application.DisplayAlerts = False

ActiveSheet.Copy
With ActiveWorkbook.ActiveSheet
Cells.Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
.Parent.SaveAs "D:\rpreijnd\Desktop\" & strFileName & ".xlsx", xlOpenXMLWorkbook
.Parent.Close False
End With

Application.DisplayAlerts = True
Application.ScreenUpdating = True

End Sub

/code

The problem is that I want the new file to be without the hidden rows and colums. I can't seem to get it right.

Also I want the cells in the new file to be as value and not as formula, I tried some code, but It messed the whole file up.

The other problem is that when I hit the cancel butten it still generates a file. What is the right code to get the action to stop if i hit cancel?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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