close

Hi All,
I'm looking for vb code to use as a macro to copy a sheet, save it as the text in cell C5, and save it in a particular directory.

Does have something that can do this?
I have got this code so far. It saves the file to my documents as the specified cell D5.
However
1.I want it to only save the 1 sheet 'Group Sign Off' instead of the 8 sheets in the workbook.
2. And it doesn't allow me to specify the save directory i.e.(quot;L:\Credit Management Team\Gareth Thomas\quot;.

does anyone know how to make these changes?

current code:

Sub SaveAsCell()
Dim strName As String

On Error GoTo InvalidName 'checks if filename D5 is valid strName = Sheets(quot;Group Sign-Offquot;).Range(quot;d5quot;) ActiveWorkbook.SaveAs strName

Exit Sub
'invalid filename output
InvalidName: MsgBox quot;The text: quot; amp; strName amp; _ quot; is not a valid file name.quot;, vbCritical, quot;Ozgrid.comquot;
End Sub
Hi again, i now have it saving to the correct directory, does anyone know how to change this to only save the sheet and not the workbook.

Thanks all

Code:

Sub SaveAsCell()
Dim strName As String

On Error GoTo InvalidName Sheets(quot;Group Sign-Offquot;).SaveAs Filename:=quot;L:\Credit Management Team\Gareth Thomas\quot; amp; _ Sheets(quot;Group Sign-Offquot;).Range(quot;d5quot;).Value amp; quot;.xlsquot;
Exit Sub
InvalidName: MsgBox quot;The text: quot; amp; strName amp; _ quot; is not a valid file name.quot;, vbCritical, quot;Ozgrid.comquot;
End Sub
GarToms,

the following macro might give you a lead... It involves Select so
there will be some flashing on the screen. Another method could be to
modify this code to loop over all cells of origin and set values and
formats of all destination cells equal. UsedRange can make this
speedier than looping over the entire sheet.

Sub SaveSheetAsCell()
Dim newbk As Workbook
Dim oldCell As Range

Set oldCell = Selection
Set newbk = Workbooks.Add(xlWBATWorksheet)

ThisWorkbook.Sheets(quot;Group Sign-Offquot;).Cells.Copy
newbk.Sheets(1).Name = quot;Group Sign-Offquot;
newbk.Sheets(quot;Group Sign-Offquot;).Select
newbk.Sheets(quot;Group Sign-Offquot;).Paste

fpath = quot;L:\Credit Management Team\Gareth Thomas\quot;
fname = Sheets(quot;Group Sign-Offquot;).Range(quot;d5quot;).Value amp; quot;.xlsquot;
newbk.SaveAs fpath amp; fname
newbk.Close

Application.CutCopyMode = False
oldCell.Select

End Sub

Does it help?
Kostis VezeridesThats excellent, thanks a lot.Originally Posted by vezeridGarToms,

the following macro might give you a lead... It involves Select so
there will be some flashing on the screen. Another method could be to
modify this code to loop over all cells of origin and set values and
formats of all destination cells equal. UsedRange can make this
speedier than looping over the entire sheet.

Sub SaveSheetAsCell()
Dim newbk As Workbook
Dim oldCell As Range

Set oldCell = Selection
Set newbk = Workbooks.Add(xlWBATWorksheet)

ThisWorkbook.Sheets(quot;Group Sign-Offquot;).Cells.Copy
newbk.Sheets(1).Name = quot;Group Sign-Offquot;
newbk.Sheets(quot;Group Sign-Offquot;).Select
newbk.Sheets(quot;Group Sign-Offquot;).Paste

fpath = quot;L:\Credit Management Team\Gareth Thomas\quot;
fname = Sheets(quot;Group Sign-Offquot;).Range(quot;d5quot;).Value amp; quot;.xlsquot;
newbk.SaveAs fpath amp; fname
newbk.Close

Application.CutCopyMode = False
oldCell.Select

End Sub

Does it help?
Kostis Vezerides

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()