PDA

View Full Version : Solved: Code makes excel crash!



Rejje
11-22-2010, 01:33 PM
HELP!

When I run below button everything works perfect until opening of the fresh workbook named whatever is in V_50200. What could be the problem?


Sub SaveThis()
Dim wb As Workbook
Set wb = ActiveWorkbook
If UCase(wb.FullName) = UCase(Range("V_50100").Value) Then
ActiveWorkbook.SaveAs Range("V_50200").Value
Workbooks.Open wb.FullName
Else
wb.Save
End If
Set wb = Nothing

End Sub

Bob Phillips
11-22-2010, 02:00 PM
What exactly are you trying to do.

SaveAs a workbook does not keep the old workbook open, the activeworkbook takes the name of the SavedAs file, so there is no point in re-opening it.

Rejje
11-22-2010, 02:13 PM
What exactly are you trying to do.

SaveAs a workbook does not keep the old workbook open, the activeworkbook takes the name of the SavedAs file, so there is no point in re-opening it.

This is the thing:

1. I write some stuff in "Template.xlsm"
2. I press a button "Save"
3. The macro should check if the workbook is called "Template.xlsm";

If true: Save as another "newvalue.xlsm" which is found in a cell that depends on texts I have written in the template; then open the newly created "newvalue.xlsm" so that I can continue to write.

If false: Save as usual

However I managed to solve the problem simply by relocating the sub to another macro. Can't vba be strange sometimes?

Aussiebear
11-22-2010, 02:24 PM
However I managed to solve the problem simply by relocating the sub to another macro. Can't vba be strange sometimes?

Sometimes what we write is considered strange. "Relocating the sub to another macro..." If this is true then the sub cannot have been the problem surely?

Rejje
11-22-2010, 02:35 PM
Sometimes what we write is considered strange. "Relocating the sub to another macro..." If this is true then the sub cannot have been the problem surely?

You're right. Still have the same problem I just discovered. It's something else. The thing is the problems began efter I tried wrote this code.

Got to reconsider this and maybe start working with a backup since I can't fix the crashing.

Thanks!

Bob Phillips
11-22-2010, 02:41 PM
All you need is



Sub SaveThis()
Dim wb As Workbook
Set wb = ActiveWorkbook
If UCase(wb.FullName) = UCase(Range("V_50100").Value) Then
wb.SaveAs Range("V_50200").Value
Else
wb.Save
End If
Set wb = Nothing

End Sub

Rejje
11-22-2010, 02:52 PM
HELP!

When I run below button everything works perfect until opening of the fresh workbook named whatever is in V_50200. What could be the problem?


Sub SaveThis()
Dim wb As Workbook
Set wb = ActiveWorkbook
If UCase(wb.FullName) = UCase(Range("V_50100").Value) Then
ActiveWorkbook.SaveAs Range("V_50200").Value
Workbooks.Open wb.FullName
Else
wb.Save
End If
Set wb = Nothing

End Sub


This works! Thanks alot man!