在outlook中粘贴特定的excel范围(Paste specific excel range in outlook)
我正在开发一个我想要自动化的Excel报告,但是,单元格的范围并未在Outlook中粘贴。
这是我的代码:
Sub Mail_Selection_Range_Outlook_Body() Dim rng As Range Dim OutApp As Object Dim OutMail As Object Set rng = Nothing On Error Resume Next ' Only send the visible cells in the selection. Set rng = Selection.SpecialCells(xlCellTypeVisible) Set rng = Sheets("Sheet1").RangeToHtml("D4:D12").SpecialCells(xlCellTypeVisible, xlTextValues) On Error GoTo 0 If rng Is Nothing Then MsgBox "The selection is not a range or the sheet is protected. " & _ vbNewLine & "Please correct and try again.", vbOKOnly Exit Sub End If With Application .EnableEvents = False .ScreenUpdating = False End With Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .To = ThisWorkbook.Sheets("Sheet2").Range("C1").Value .CC = "" .BCC = "" .Subject = "This is the Subject line" .HTMLBody = RangeToHtml.rng ' In place of the following statement, you can use ".Display" to ' display the e-mail message. .Display End With On Error GoTo 0 With Application .EnableEvents = True .ScreenUpdating = True End With Set OutMail = Nothing Set OutApp = Nothing End Sub
我没有收到任何错误,只是它不会在Outlook中粘贴范围。 谢谢。
I am working on an excel report that I want to automate, however, the range of the cells are not being pasted in Outlook.
Here is my code:
Sub Mail_Selection_Range_Outlook_Body() Dim rng As Range Dim OutApp As Object Dim OutMail As Object Set rng = Nothing On Error Resume Next ' Only send the visible cells in the selection. Set rng = Selection.SpecialCells(xlCellTypeVisible) Set rng = Sheets("Sheet1").RangeToHtml("D4:D12").SpecialCells(xlCellTypeVisible, xlTextValues) On Error GoTo 0 If rng Is Nothing Then MsgBox "The selection is not a range or the sheet is protected. " & _ vbNewLine & "Please correct and try again.", vbOKOnly Exit Sub End If With Application .EnableEvents = False .ScreenUpdating = False End With Set OutApp = CreateObject("Outlook.Application") Set OutMail = OutApp.CreateItem(0) On Error Resume Next With OutMail .To = ThisWorkbook.Sheets("Sheet2").Range("C1").Value .CC = "" .BCC = "" .Subject = "This is the Subject line" .HTMLBody = RangeToHtml.rng ' In place of the following statement, you can use ".Display" to ' display the e-mail message. .Display End With On Error GoTo 0 With Application .EnableEvents = True .ScreenUpdating = True End With Set OutMail = Nothing Set OutApp = Nothing End Sub
I am not getting any error, it's just that it does not paste range in outlook. Thank you.
原文:https://stackoverflow.com/questions/18663127
最满意答案
这是我用来创建随机字符串的代码
@spec random_string(integer) :: binary def random_string(length) do length |> :crypto.strong_rand_bytes |> Base.url_encode64 |> binary_part(0, length) end
unique_constraint的问题在于,在尝试写入数据库之前,您的变更集不会显示约束错误(Repo.insert或Repo.update)
最简单的方法是使用单独的模块来处理插入。 像这样的东西:
defmodule PostService do def insert_post(params) do changeset = Post.changeset(%Post{}, params) case Repo.insert changeset do {:error, %{errors: constraint_match}} -> # constraint_error is just a placeholder for the correct match insert_post(params) error_or_ok -> error_or_ok end end end
但是,如果您使用UUID,我认为您不必担心冲突。
Here is the code I use for creating random strings
@spec random_string(integer) :: binary def random_string(length) do length |> :crypto.strong_rand_bytes |> Base.url_encode64 |> binary_part(0, length) end
The problem with unique_constraint is that your changeset won't show the constraint error until the write to the datebase is attempted (Repo.insert or Repo.update)
The simplest approach would be to use a separate module to handle the insert. Something like this:
defmodule PostService do def insert_post(params) do changeset = Post.changeset(%Post{}, params) case Repo.insert changeset do {:error, %{errors: constraint_match}} -> # constraint_error is just a placeholder for the correct match insert_post(params) error_or_ok -> error_or_ok end end end
However, if you use a UUID, I don't think you need to worry about collisions.
相关问答
更多-
Linq-To-SQL(以及实体框架)不支持唯一键,因此没有注释可确保在数据库中为您生成唯一约束。 您必须始终使用某些部署后脚本添加唯一约束/索引。 Linq-To-SQL (as well as Entity Framework) has no support for unique keys and because of that there is no annotation which will ensure that unique constraint will be generated in the ...
-
唯一约束JayData(Unique constraint JayData)[2022-02-19]
如果您不需要自动生成的id字段,则将name声明为key并计算false,这样它将是一个唯一字段。 如果你想保留id字段,那么你可以使用一个唯一的索引来实现你想要的。 索引支持在专业提供商中。 If you do not need autogenerated id field then declare name as key and computed false so it will be a unique field. If you want to keep the id field then you c ... -
主键与唯一约束?(Primary Key versus Unique Constraint?)[2024-01-03]
你能提供这些文章的参考吗? 我没有理由改变尝试和真实的方法。 毕竟,主键是关系数据库的基本设计功能。 使用UNIQUE服务于相同的目的听起来真的是对我的伤害。 他们的理由是什么? 编辑:我的注意力已经回到了这个旧的答案。 也许您阅读的关于PK与UNIQUE的讨论可以解决人们制作PK的唯一目的,以便强制执行其唯一性。 这样做的答案是,如果它是一个关键字,那么使其成为关键,否则使其成为唯一。 Can you provide references to these articles? I see no reaso ... -
我对这个基本但重要的问题有些疑问,所以我决定以身作则。 我们创建具有两列的测试表主 ,具有唯一约束的con_id和由唯一索引编制的ind_id 。 create table master ( con_id integer unique, ind_id integer ); create unique index master_unique_idx on master (ind_id); Table "public.master" Column | Type | Modifi ...
-
主键在定义上是唯一的键。 在这个例子中,它只是一个重复的不必要的密钥。 在其他情况下,如果主键可能是复合的(由两个或多个字段组成),则这样的二级索引将允许单独处理主键的各个组件。 例如: create table X { a char, b char, primary key (a,b) } 如果您使用WHERE b=something执行查询,则不会使用主键索引,因为B的索引条目与'a'绑定,并且您在查询中不使用'a'。 添加一个专用于B的次级索引可以使索引用于此where子句。 ...
-
这些将是违反唯一键约束的所有对象: var violatingObjects = listOfObjectsToAdd .Where(o => context.Objects.Any(oInDb => oInDb.AbsoluteCounter == o.AbsoluteCounter && oInDb.TimeMfrAudit == o.TimeMfrAudit)) .ToList(); 它是列表中每个对象的一个EXISTS数据库查询。 如果您只想知道违反 ...
-
您可以在系统目录中查询唯一约束 ,尤其是pg_constraint和pg_attribute : SELECT c.conname, pg_get_constraintdef(c.oid) FROM pg_constraint c JOIN ( SELECT array_agg(attnum::int) AS attkey FROM pg_attribute WHERE attrelid = 'tb'::regclass -- table name optionally sc ...
-
尝试在更新后使用session.flush()。 Try to use session.flush() after the update.
-
我一开始并没有意识到外键是引用索引而不是字段。 因此,通过在同一字段上创建新的主键并不意味着外键切换到新索引。 我现在使用级联删除了唯一约束并重新添加了所有外键,它们现在使用主键。 I didn't realize at first that the foreign keys are referencing a index rather than a field. So by creating a new primary key on the same field didn't mean that the ...
-
这是我用来创建随机字符串的代码 @spec random_string(integer) :: binary def random_string(length) do length |> :crypto.strong_rand_bytes |> Base.url_encode64 |> binary_part(0, length) end unique_constraint的问题在于,在尝试写入数据库之前,您的变更集不会显示约束错误(Repo.insert或Repo.update) 最简单 ...